HomeController.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. using NEducation.Code;
  2. using NEducation.Content.Texts;
  3. using NEducation.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Linq;
  8. using System.ServiceModel;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. using System.IO;
  12. using System.Globalization;
  13. using System.Linq;
  14. using System.Threading;
  15. using System.Web.SessionState;
  16. using Newtonsoft.Json;
  17. using System.Net.Sockets;
  18. using System.Net;
  19. using System.Security.Policy;
  20. using Microsoft.Extensions.Configuration;
  21. using System.Threading.Tasks;
  22. using System.Net.Http;
  23. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  24. using log4net.Core;
  25. using Newtonsoft.Json.Serialization;
  26. using Devart.Common;
  27. namespace NEducation.Controllers
  28. {
  29. public class HomeController : BaseController
  30. {
  31. private static log4net.ILog log { get; set; } = log4net.LogManager.GetLogger(typeof(HomeController));
  32. GenKeyWs.WsGenKeyClient wsClient = new GenKeyWs.WsGenKeyClient();
  33. public ActionResult Index(String token)
  34. {
  35. HomeModel model = new HomeModel();
  36. if (token != null)
  37. {
  38. log.Info("login_camid:");
  39. Session["navitab"] = "Home";
  40. //HomeModel model = new HomeModel();
  41. // nhan dien thue bao
  42. String msisdnAuto = null;
  43. model.uuid = token;
  44. log.Info("uuid: " + token);
  45. HttpCookie reqCookies = Request.Cookies["onapp"];
  46. if (reqCookies != null)
  47. {
  48. string isOnApp = reqCookies["isonapp"].ToString();
  49. if (isOnApp == "1")
  50. {
  51. Session["WHICHDEVICE"] = UtilsController.Constant.REGISTER_ON_APP;
  52. }
  53. }
  54. Session["Token"] = token;
  55. String msisdnToken = getUserFromToken(token);
  56. log.Info("msisdn: " + msisdnToken);
  57. if (msisdnToken != "")
  58. {
  59. //String resDetect = CheckAutoLogin(log, msisdnToken);
  60. //log.Info("token: " + token + " res: " + resDetect);
  61. //if (resDetect != null)
  62. //{
  63. // dynamic json = JsonConvert.DeserializeObject(resDetect);
  64. // log.Info("res json: " + json);
  65. // String code = json["code"];
  66. // if (code == "200")
  67. // {
  68. // String errorCode = json["errorCode"];
  69. // if (errorCode == "200")
  70. // {
  71. // msisdnAuto = json["data"]["msisdn"];
  72. // log.Info("msisdnAuto: " + msisdnAuto);
  73. // }
  74. // auto login
  75. // reload user info
  76. HttpContext.Session.Remove("regInfos");
  77. Session["msisdnDetect"] = msisdnToken;
  78. // dang ky tren app
  79. Session["WHICHDEVICE"] = UtilsController.Constant.REGISTER_ON_APP;
  80. HttpCookie onApp = new HttpCookie("onapp");
  81. onApp["isonapp"] = "1";
  82. onApp.Expires = DateTime.Now.AddDays(30);
  83. Response.Cookies.Add(onApp);
  84. // check user has account
  85. GetUserProfileReq req = new GetUserProfileReq();
  86. req.users = msisdnToken;
  87. String rs = UtilsController.SendPost(req, System.Web.HttpContext.Current.Session.SessionID, UtilsController.WsType.UsersGetProfile);
  88. UserProfile profile = new UserProfile(rs);
  89. if (profile.id != null)
  90. {
  91. System.Web.HttpContext.Current.Session["profile"] = profile;
  92. // create new auth
  93. CreateAuthToken();
  94. String sessionId = Session.SessionID;
  95. // login success --> store session
  96. Session["msisdn"] = msisdnToken;
  97. Session["Token"] = token;
  98. // get sub
  99. UtilsController.ReloadSubInfo();
  100. // all info of user was loaded from server
  101. //UserProfile profile = Session["profile"] as UserProfile;
  102. String typeLanguage = Session["typeLanguage"] as String;
  103. }
  104. else
  105. {
  106. // Create a free account for the user
  107. UserRequest userRequest = new UserRequest
  108. {
  109. users = msisdnToken,
  110. msisdn = msisdnToken,
  111. command = "REGIST",
  112. channel = "WEB"
  113. };
  114. string rsRegister = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister);
  115. UserActionResult resRegister = new UserActionResult(rsRegister);
  116. Session["isSub"] = "false";
  117. if (resRegister.status == UtilsController.Constant.SUCCESS)
  118. {
  119. // Load profile
  120. GetUserProfileReq reqProfile = new GetUserProfileReq { users = msisdnToken };
  121. string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile);
  122. UserProfile profileGet = new UserProfile(rsProfile);
  123. if (profileGet.id != null)
  124. {
  125. Session["profile"] = profileGet;
  126. UserInfoRequest reqStatus = new UserInfoRequest { users = msisdnToken };
  127. string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus);
  128. UserActionResult resStatus = new UserActionResult(rsStatus);
  129. if (resStatus.status == UtilsController.Constant.SUCCESS)
  130. {
  131. UserInfo userInfo = new UserInfo(rsStatus);
  132. Session["userInfo"] = userInfo;
  133. Session["Token"] = token;
  134. // Create new auth
  135. CreateAuthToken();
  136. Session["msisdn"] = msisdnToken;
  137. // Reload user info
  138. UtilsController.ReloadSubInfo();
  139. }
  140. }
  141. }
  142. }
  143. // }
  144. //}
  145. }
  146. return View(model);
  147. }
  148. else
  149. {
  150. Session["WHICHDEVICE"] = UtilsController.Constant.REGISTER_ON_WEB;
  151. return View(model);
  152. }
  153. return null;
  154. }
  155. private string getUserFromToken(string token)
  156. {
  157. String resGet = GetUserInfoFromApp(token);
  158. log.Info(" get user from app result: " + resGet);
  159. if (resGet != null && resGet != "")
  160. {
  161. dynamic json = JsonConvert.DeserializeObject(resGet);
  162. log.Info("res json: " + json);
  163. String code = json["code"];
  164. if (code == "00")
  165. {
  166. String msisdnAuto = json["data"]["user"]["phone_number"];
  167. String userName = json["data"]["user"]["username"];
  168. log.Info("msisdnAuto: " + msisdnAuto);
  169. log.Info("userName: " + userName);
  170. // check phone number
  171. String msisdn = UtilsController.validateMsisdn(msisdnAuto);
  172. if (msisdn != null && msisdn != "")
  173. {
  174. Session["msisdn"] = msisdn;
  175. //Session["channel"] = "2";
  176. //Response.Cookies["channel"].Value = "2";
  177. //Response.Cookies["token"].Value = token;
  178. //ServiceLogin.WsGamePortalClient wsClient = new ServiceLogin.WsGamePortalClient();
  179. //SetWsClient(ref wsClient, Session.SessionID);
  180. //ServiceLogin.response wsResponse = ReloadAccountInfo(msisdn);
  181. //if (wsResponse.msisdn != null && wsResponse.msisdn.Length > 0)
  182. //{
  183. // CreateAuthToken();
  184. //}
  185. return msisdn;
  186. }
  187. }
  188. }
  189. return null;
  190. }
  191. public string GetUserInfoFromApp(string token)
  192. {
  193. string res = null;
  194. try
  195. {
  196. ServicePointManager.Expect100Continue = true;
  197. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  198. using (HttpClient httpClient = new HttpClient())
  199. {
  200. httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
  201. httpClient.DefaultRequestHeaders.Add("accessToken", ConfigurationManager.AppSettings["accessToken"]);
  202. // Ghi log tất cả các header
  203. log.Info("Headers:");
  204. foreach (var header in httpClient.DefaultRequestHeaders)
  205. {
  206. log.Info($"{header.Key}: {string.Join(", ", header.Value)}");
  207. }
  208. log.Info("Req " + ConfigurationManager.AppSettings["pathDetectUser"]);
  209. HttpResponseMessage response = httpClient.GetAsync(ConfigurationManager.AppSettings["pathDetectUser"]).Result;
  210. log.Info("response " + response.ToString());
  211. response.EnsureSuccessStatusCode();
  212. res = response.Content.ReadAsStringAsync().Result;
  213. }
  214. }
  215. catch (Exception ex)
  216. {
  217. log.Error(ex);
  218. }
  219. return res;
  220. }
  221. public ActionResult VietnameseIndex()
  222. {
  223. // check login
  224. try
  225. {
  226. if (!CheckAuthToken())
  227. {
  228. // show login dialog
  229. return Redirect("/Home/Index");
  230. }
  231. }
  232. catch (Exception exp)
  233. {
  234. System.Diagnostics.Debug.WriteLine("Exception: " + exp);
  235. }
  236. Session["COURSE_NOW"] = UtilsController.Constant.VIETNAMESE;
  237. return View("VietnameseIndex");
  238. }
  239. public ActionResult LaosIndex()
  240. {
  241. if (!CheckAuthToken())
  242. {
  243. // show login dialog
  244. return Redirect("/Home/Index");
  245. }
  246. Session["COURSE_NOW"] = UtilsController.Constant.LAOS;
  247. return View("LaosIndex");
  248. }
  249. public ActionResult EnglishIndex()
  250. {
  251. if (!CheckAuthToken())
  252. {
  253. // show login dialog
  254. return Redirect("/Home/Index");
  255. }
  256. Session["COURSE_NOW"] = UtilsController.Constant.ENGLISH;
  257. return View("EnglishIndex");
  258. }
  259. public JsonResult CheckAccount(String typeCourse)
  260. {
  261. Session["typeLanguage"] = typeCourse;
  262. if (!CheckAuthToken())
  263. {
  264. return Json(new
  265. {
  266. code = "-1",
  267. });
  268. }
  269. return Json(new
  270. {
  271. code = "0",
  272. });
  273. }
  274. public JsonResult CheckButton(String msisdn)
  275. {
  276. String mToken = Session["Token"] as String;
  277. return Json(new
  278. {
  279. token = mToken,
  280. msisdn = msisdn,
  281. });
  282. }
  283. public JsonResult CourseSet(String courseId)
  284. {
  285. Session["COURSE_NOW"] = courseId;
  286. return Json(new
  287. {
  288. code = "0",
  289. });
  290. }
  291. public ActionResult ChangeLanguage(String LanguageAbbrevation)
  292. {
  293. if (CheckAuthToken())
  294. {
  295. System.Diagnostics.Debug.WriteLine("LanguageAbbrevation: " + LanguageAbbrevation);
  296. if (LanguageAbbrevation != null)
  297. {
  298. Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(LanguageAbbrevation);
  299. Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageAbbrevation);
  300. }
  301. //Response.Cookies.Remove("Language");
  302. HttpCookie cookie = new HttpCookie("Language");
  303. cookie.Value = LanguageAbbrevation;
  304. Response.Cookies.Add(cookie);
  305. String mMsisdn = Session["msisdn"] as String;
  306. String lang = "1";
  307. if (LanguageAbbrevation == "en")
  308. {
  309. lang = "0";
  310. }
  311. SetLanguageRequest reqStatus = new SetLanguageRequest
  312. {
  313. users = mMsisdn,
  314. language = lang
  315. };
  316. string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.usersSetLanguage);
  317. SetLanguageResult resStatus = new SetLanguageResult(rsStatus);
  318. if (resStatus.status == UtilsController.Constant.SUCCESS)
  319. {
  320. log.Debug("ChangeLanguage_SUCCESS");
  321. }
  322. else
  323. {
  324. log.Debug("ChangeLanguage_Faild");
  325. }
  326. return View();
  327. }
  328. else
  329. {
  330. Session.Clear();
  331. return Redirect("/Home/Index");
  332. }
  333. }
  334. [ValidateAntiForgeryToken]
  335. public async Task<JsonResult> RegisterSub(string captcha, string phone, string otp)
  336. {
  337. try
  338. {
  339. log.Debug("RegisterSub: " + phone);
  340. String packageName = ConfigurationManager.AppSettings["packname"];
  341. String REGISTER_ToBe = ConfigurationManager.AppSettings["packNameREGISTER_ToBe"];
  342. String fee = ConfigurationManager.AppSettings["fee"];
  343. // check account existed
  344. var checkSub = UtilsController.checkAccountSub(phone, REGISTER_ToBe);
  345. if (checkSub == false)
  346. {
  347. // Tạo đối tượng mpsparams với các giá trị từ tham số
  348. MpsParams mpsparams = new MpsParams
  349. {
  350. CMD = "REGISTER",
  351. PRICE = fee,
  352. MOBILE = phone,
  353. CATE = "BLANK",
  354. SUB = packageName
  355. };
  356. // Gọi phương thức bất đồng bộ để đăng ký
  357. GenKeyWs.response makeUrl = await WapController.UserRegisteringAsync(wsClient, mpsparams);
  358. // Lưu thông tin vào session
  359. Session["mps-params"] = mpsparams;
  360. log.Debug("mpsparams_RegisterSub: " + mpsparams);
  361. log.Debug("makeUrl_RegisterSub: " + makeUrl);
  362. // Kiểm tra mã lỗi và trả về kết quả tương ứng
  363. if (makeUrl.errorCode == UtilsController.WapConstant.SUCCESS)
  364. {
  365. return Json(new
  366. {
  367. success = true,
  368. redirectUrl = makeUrl.enscrypt
  369. });
  370. }
  371. else
  372. {
  373. return Json(new
  374. {
  375. success = false,
  376. error_code = makeUrl.errorCode,
  377. error_content = UtilsController.GetErrorCodeCharging(makeUrl.errorCode)
  378. });
  379. }
  380. }
  381. else
  382. {
  383. return Json(new
  384. {
  385. success = true,
  386. redirectUrl = "/Home/Index"
  387. });
  388. }
  389. }
  390. catch (Exception ex)
  391. {
  392. // Log lỗi nếu cần
  393. return Json(new
  394. {
  395. success = false,
  396. error_code = "UNKNOWN_ERROR",
  397. error_content = "An unexpected error occurred: "
  398. });
  399. }
  400. }
  401. //[ValidateAntiForgeryToken]
  402. //public async Task<ActionResult> RegisterSub(string captcha, string phone, string otp)
  403. //{
  404. // try
  405. // {
  406. // string packageName = ConfigurationManager.AppSettings["packname"];
  407. // string fee = ConfigurationManager.AppSettings["fee"];
  408. // // Tạo đối tượng mpsparams với các giá trị từ tham số
  409. // MpsParams mpsparams = new MpsParams
  410. // {
  411. // CMD = "REGISTER",
  412. // PRICE = fee,
  413. // MOBILE = phone,
  414. // CATE = "BLANK",
  415. // SUB = packageName
  416. // };
  417. // // Gọi phương thức bất đồng bộ để đăng ký
  418. // GenKeyWs.response makeUrl = await WapController.UserRegisteringAsync(wsClient, mpsparams);
  419. // // Lưu thông tin vào session
  420. // Session["mps-params"] = mpsparams;
  421. // // Kiểm tra mã lỗi và trả về kết quả tương ứng
  422. // if (makeUrl.errorCode == UtilsController.WapConstant.SUCCESS)
  423. // {
  424. // return Redirect(makeUrl.enscrypt); // Điều hướng đến URL thành công
  425. // }
  426. // else
  427. // {
  428. // // Nếu không thành công, trả về một lỗi hoặc thông báo
  429. // return Json(new
  430. // {
  431. // success = false,
  432. // error_code = makeUrl.errorCode,
  433. // error_content = UtilsController.GetErrorCodeCharging(makeUrl.errorCode)
  434. // }, JsonRequestBehavior.AllowGet);
  435. // }
  436. // }
  437. // catch (Exception ex)
  438. // {
  439. // // Log lỗi nếu cần
  440. // return Json(new
  441. // {
  442. // success = false,
  443. // error_code = "UNKNOWN_ERROR",
  444. // error_content = "An unexpected error occurred."
  445. // }, JsonRequestBehavior.AllowGet);
  446. // }
  447. //}
  448. [ValidateAntiForgeryToken]
  449. public JsonResult RegisterSubWithoutCaptcha()
  450. {
  451. if (!CheckAuthToken())
  452. {
  453. return Json(new
  454. {
  455. error_code = UtilsController.Constant.EXCEPTION,
  456. error_content = ErrCode.SystemErr
  457. });
  458. }
  459. String msisdn = Session["msisdn"] as string;
  460. String whichDevice = Session["WHICHDEVICE"] as String;
  461. if (msisdn != "" && msisdn != null)
  462. {
  463. // get package
  464. String packageId = Session["COURSE_NOW"] as String;
  465. String package = UtilsController.GetPackagename(packageId, whichDevice, "REGISTER");
  466. // check account existed
  467. var checkSub = UtilsController.checkAccountSub(msisdn, package);
  468. if (checkSub == false)
  469. {
  470. //AbandonSession();
  471. UserRequest userRequest = new UserRequest();
  472. userRequest.users = msisdn;
  473. userRequest.msisdn = msisdn;
  474. userRequest.subServiceCode = package;
  475. userRequest.requestId = "-1";
  476. userRequest.otp = "-1";
  477. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest);
  478. UserActionResult res = new UserActionResult(rs);
  479. if (res.responseCode == UtilsController.Constant.WAITING_OTP)
  480. //if (res.responseCode == UtilsController.Constant.SUCCESS) // for test
  481. {
  482. Charging charging = new Charging(rs);
  483. Session["charging"] = charging;
  484. Session["msisdn"] = msisdn;
  485. Session["package"] = package;
  486. Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER;
  487. Session["CHARGE_DATA"] = userRequest;
  488. }
  489. return Json(new
  490. {
  491. error_code = res.responseCode,
  492. error_content = UtilsController.GetErrorCodeCharging(res.responseCode)
  493. });
  494. }
  495. else
  496. {
  497. return Json(new
  498. {
  499. error_code = UtilsController.Constant.USER_EXISTED,
  500. error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED)
  501. });
  502. }
  503. }
  504. else
  505. {
  506. return Json(new
  507. {
  508. error_code = UtilsController.Constant.INVALID_MSISDN,
  509. error_content = Lang.InvalidMsisdn,
  510. });
  511. }
  512. }
  513. [ValidateAntiForgeryToken]
  514. public JsonResult ResentOtp()
  515. {
  516. String msisdn = Session["msisdn"] as string;
  517. if (msisdn != "" && msisdn != null)
  518. {
  519. String chargeAction = Session["CHARGE_ACTION"] as String;
  520. UserRequest chargerequest = Session["CHARGE_DATA"] as UserRequest;
  521. if (chargeAction == UtilsController.Constant.REGISTER)
  522. {
  523. // get package
  524. String whichDevice = Session["WHICHDEVICE"] as String;
  525. String packageId = Session["COURSE_NOW"] as String;
  526. String package = UtilsController.GetPackagename(packageId, whichDevice, "REGISTER");
  527. String rs = UtilsController.SendPost(chargerequest, Session.SessionID, UtilsController.WsType.MpsRequest);
  528. UserActionResult res = new UserActionResult(rs);
  529. if (res.responseCode == UtilsController.Constant.WAITING_OTP)
  530. //if (res.responseCode == UtilsController.Constant.SUCCESS) // for test
  531. {
  532. Charging charging = new Charging(rs);
  533. Session["charging"] = charging;
  534. Session["msisdn"] = msisdn;
  535. Session["package"] = package;
  536. }
  537. return Json(new
  538. {
  539. error_code = res.responseCode,
  540. error_content = Lang.otpSentAgain
  541. });
  542. }
  543. else
  544. {
  545. String rs = UtilsController.SendPost(chargerequest, Session.SessionID, UtilsController.WsType.buyCourse);
  546. UserActionResult res = new UserActionResult(rs);
  547. System.Diagnostics.Debug.WriteLine(rs);
  548. if (res.status == UtilsController.Constant.WAITING_OTP)
  549. //if (res.status == UtilsController.Constant.SUCCESS) // for test
  550. {
  551. Charging charging = new Charging(rs);
  552. Session["charging"] = charging;
  553. }
  554. return Json(new
  555. {
  556. error_code = res.status,
  557. error_content = UtilsController.GetErrorCodeCharging(res.status),
  558. });
  559. }
  560. }
  561. else
  562. {
  563. return Json(new
  564. {
  565. error_code = UtilsController.Constant.EXCEPTION,
  566. });
  567. }
  568. }
  569. [HttpPost]
  570. public ActionResult UploadImage(HttpPostedFileBase file)
  571. {
  572. if (CheckAuthToken())
  573. {
  574. System.Diagnostics.Debug.WriteLine("file: " + file);
  575. // check type of file
  576. if (file != null && file.ContentLength > 0)
  577. try
  578. {
  579. var supportedTypes = new[] { "jpg", "png" };
  580. var fileExt = Path.GetExtension(file.FileName).Substring(1);
  581. System.Diagnostics.Debug.WriteLine("fileExt: " + fileExt);
  582. System.Diagnostics.Debug.WriteLine("file.ContentLength: " + file.ContentLength);
  583. if (!supportedTypes.Contains(fileExt))
  584. {
  585. //return Json(new
  586. //{
  587. // error_content = "File Extension Is InValid - Only Upload WORD/PDF/EXCEL/TXT File",
  588. //});
  589. ViewBag.Message = "File Extension Is InValid - Only Upload WORD/PDF/EXCEL/TXT File";
  590. return View("ProfileView");
  591. }
  592. else if (file.ContentLength > (5 * 1024 * 1024))
  593. {
  594. //return Json(new
  595. //{
  596. // error_content = "File size Should Be UpTo " + 5 + "MB",
  597. //});
  598. ViewBag.Message = "File size Should Be UpTo 5MB";
  599. return View("ProfileView");
  600. }
  601. else
  602. {
  603. //string path = Path.Combine(Server.MapPath("~/Images"),
  604. // Path.GetFileName(file.FileName));
  605. var msisdn = Session["msisdn"] as string;
  606. System.Diagnostics.Debug.WriteLine("msisdn: " + msisdn);
  607. if (msisdn != null)
  608. {
  609. System.Diagnostics.Debug.WriteLine("FileName: " + Path.GetFileName(file.FileName));
  610. var fileName = msisdn + "_" + Path.GetFileName(file.FileName);
  611. var path = Path.Combine(Server.MapPath("~/Content/assets/imgs/post/"), fileName);
  612. System.Diagnostics.Debug.WriteLine("path: " + path);
  613. file.SaveAs(path);
  614. ViewBag.Message = "File uploaded successfully";
  615. ProfileModel model = new ProfileModel();
  616. UserProfile userProfile = Session["profile"] as UserProfile;
  617. // update icon
  618. userProfile.picture = UtilsController.GetContentPath.IndividualContentPath + fileName;
  619. String rs = UtilsController.SendPost(userProfile, Session.SessionID, UtilsController.WsType.UsersUpdateProfile);
  620. UserActionResult res = new UserActionResult(rs);
  621. if (res.status == UtilsController.Constant.SUCCESS)
  622. {
  623. // update success --> store session
  624. Session["profile"] = userProfile;
  625. }
  626. else
  627. {
  628. return Redirect("/Common/Error");
  629. }
  630. model.profileDetail = userProfile;
  631. return View("ProfileView", model);
  632. }
  633. else
  634. {
  635. ViewBag.Message = "File uploaded failure";
  636. return Redirect("/Common/Error");
  637. }
  638. }
  639. }
  640. catch (Exception ex)
  641. {
  642. ViewBag.Message = "ERROR:" + ex.Message.ToString();
  643. return Redirect("/Common/Error");
  644. }
  645. else
  646. {
  647. ViewBag.Message = "You have not specified a file.";
  648. return Redirect("/Common/Error");
  649. }
  650. }
  651. else
  652. {
  653. Session.Clear();
  654. return Redirect("/Home/Index");
  655. }
  656. }
  657. [HttpPost]
  658. public ActionResult UploadExistedImage(String picture)
  659. {
  660. if (CheckAuthToken())
  661. {
  662. // check type of file
  663. if (picture != null)
  664. {
  665. UserProfile userProfile = Session["profile"] as UserProfile;
  666. // update icon
  667. userProfile.picture = picture;
  668. String rs = UtilsController.SendPost(userProfile, Session.SessionID, UtilsController.WsType.UsersUpdateProfile);
  669. UserActionResult res = new UserActionResult(rs);
  670. if (res.status == UtilsController.Constant.SUCCESS)
  671. {
  672. // update success --> store session
  673. Session["profile"] = userProfile;
  674. }
  675. return Json(new
  676. {
  677. error_code = res.status,
  678. error_content = UtilsController.GetErrorCodeCharging(res.status),
  679. });
  680. }
  681. else
  682. {
  683. ViewBag.Message = "You have not specified a file.";
  684. return Redirect("/Common/Error");
  685. }
  686. }
  687. else
  688. {
  689. Session.Clear();
  690. return Redirect("/Home/Index");
  691. }
  692. }
  693. [ValidateAntiForgeryToken]
  694. public JsonResult CreateFree(String captcha, String phone)
  695. {
  696. try
  697. {
  698. if (!ReCaptcha.Validate(captcha))
  699. {
  700. return Json(new
  701. {
  702. error_code = UtilsController.Constant.USER_EXISTED,
  703. error_content = "Your captcha is not valid"
  704. });
  705. }
  706. String msisdn = UtilsController.validateMsisdn(phone);
  707. if (msisdn != "")
  708. {
  709. //AbandonSession();
  710. UserRequest userRequest = new UserRequest();
  711. userRequest.users = msisdn;
  712. userRequest.msisdn = msisdn;
  713. userRequest.command = "REGIST";
  714. userRequest.channel = "WEB";
  715. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister);
  716. System.Diagnostics.Debug.WriteLine("res: " + rs);
  717. UserActionResult res = new UserActionResult(rs);
  718. Session["isSub"] = "false";
  719. return Json(new
  720. {
  721. error_code = res.status,
  722. error_content = UtilsController.GetErrorCodeCharging(res.status),
  723. href = res.status == UtilsController.Constant.SUCCESS ? "/Home/Login" : null,
  724. //href = res.status == UtilsController.Constant.SUCCESS ? "/Home/Login" : null // for test
  725. });
  726. }
  727. else
  728. {
  729. return Json(new
  730. {
  731. error_code = UtilsController.Constant.INVALID_MSISDN,
  732. error_content = Lang.InvalidMsisdn,
  733. });
  734. }
  735. }
  736. catch (Exception ex)
  737. {
  738. return Json(new
  739. {
  740. error_code = UtilsController.Constant.EXCEPTION,
  741. error_content = UtilsController.GetErrorCodeCharging("-10"),
  742. });
  743. }
  744. }
  745. public ActionResult LoginSuccess(String code)
  746. {
  747. try
  748. {
  749. // verify
  750. String tempCode = code;
  751. log.Info("Login success: code = " + code + ", tempCode = " + tempCode);
  752. Verify.VerifyReq req = new Verify.VerifyReq();
  753. req.code = code;
  754. req.secretKey = ConfigurationManager.AppSettings["secretKey"];
  755. string url = ConfigurationManager.AppSettings["uniIdVerifier"];
  756. String result = UtilsController.SendPostWithAuthen(req, url, ConfigurationManager.AppSettings["secretKey"]);
  757. Verify.VerifyRes res = Verify.VerifyRes.Parse(result);
  758. if (res.status == 100)
  759. {
  760. // success -> check token
  761. String token = res.data.accessToken;
  762. Dictionary<String, String> headers = new Dictionary<string, string>();
  763. headers.Add("Authorization", "Bearer " + token);
  764. result = UtilsController.SendGetWithAuthen(ConfigurationManager.AppSettings["uniIdUsers"], token);
  765. Verify.UserRes users = Verify.UserRes.Parse(result);
  766. if (users.status == 100)
  767. {
  768. // success
  769. // login success --> store session
  770. String msisdn = UtilsController.validateMsisdn(users.data.phone);
  771. // create new auth
  772. CreateAuthToken();
  773. String sessionId = Session.SessionID;
  774. // login success --> store session
  775. Session["msisdn"] = msisdn;
  776. // get profile
  777. UtilsController.ReloadProfileInfo();
  778. UserProfile profile = Session["profile"] as UserProfile;
  779. if (profile != null)
  780. {
  781. // get sub
  782. UtilsController.ReloadSubInfo();
  783. }
  784. else
  785. {
  786. // create account
  787. UserRequest userRequest = new UserRequest();
  788. userRequest.users = msisdn;
  789. userRequest.msisdn = msisdn;
  790. userRequest.command = "REGIST";
  791. userRequest.channel = "WEB";
  792. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister);
  793. System.Diagnostics.Debug.WriteLine("res: " + rs);
  794. UtilsController.ReloadSubInfo();
  795. }
  796. }
  797. }
  798. return Redirect("/Home");
  799. }
  800. catch (Exception ex)
  801. {
  802. log.Error("Exception login success: " + ex.Message, ex);
  803. return Redirect("/Error");
  804. }
  805. }
  806. [ValidateAntiForgeryToken]
  807. public JsonResult Login(String phoneNumber, String password, String typeLang)
  808. {
  809. try
  810. {
  811. String msisdn = UtilsController.validateMsisdn(phoneNumber);
  812. if (msisdn != "" && msisdn != null)
  813. {
  814. //AbandonSession();
  815. UserInfoRequest user = new UserInfoRequest();
  816. user.users = msisdn;
  817. user.msisdn = msisdn;
  818. user.pass = password;
  819. user.command = "LOGIN";
  820. user.channel = "WEB";
  821. String rs = UtilsController.SendPost(user, Session.SessionID, UtilsController.WsType.UsersRegister);
  822. UserActionResult res = new UserActionResult(rs);
  823. // fake
  824. if (msisdn == "8562098376035")
  825. {
  826. // create new auth
  827. CreateAuthToken();
  828. String sessionId = Session.SessionID;
  829. // login success --> store session
  830. Session["msisdn"] = msisdn;
  831. // get profile
  832. UtilsController.ReloadProfileInfo();
  833. // get sub
  834. UtilsController.ReloadSubInfo();
  835. // all info of user was loaded from server
  836. //UserProfile profile = Session["profile"] as UserProfile;
  837. String typeLanguage = Session["typeLanguage"] as String;
  838. // check sub
  839. String isSub = Session["isSub"] as String;
  840. //HttpCookie onApp = new HttpCookie("onapp");
  841. //onApp["isonapp"] = "1";
  842. //onApp.Expires = DateTime.Now.AddDays(30);
  843. //Response.Cookies.Add(onApp);
  844. return Json(new
  845. {
  846. error_code = "0",
  847. error_content = "Success",
  848. msisdn = msisdn.Substring(UtilsController.CountryCode.Length),
  849. href = typeLanguage == UtilsController.Constant.LAOS ? "/Home/LaosIndex" :
  850. typeLanguage == UtilsController.Constant.VIETNAMESE ? "/Home/VietnameseIndex" :
  851. typeLanguage == UtilsController.Constant.ENGLISH ? "/Home/EnglishIndex" : "/Home/Index"
  852. });
  853. }
  854. else if (res.status == UtilsController.Constant.SUCCESS)
  855. {
  856. // create new auth
  857. CreateAuthToken();
  858. String sessionId = Session.SessionID;
  859. // login success --> store session
  860. Session["msisdn"] = msisdn;
  861. // get profile
  862. UtilsController.ReloadProfileInfo();
  863. // get sub
  864. UtilsController.ReloadSubInfo();
  865. // all info of user was loaded from server
  866. //UserProfile profile = Session["profile"] as UserProfile;
  867. String typeLanguage = Session["typeLanguage"] as String;
  868. //HttpCookie onApp = new HttpCookie("onapp");
  869. //onApp["isonapp"] = "1";
  870. //onApp.Expires = DateTime.Now.AddDays(30);
  871. //Response.Cookies.Add(onApp);
  872. return Json(new
  873. {
  874. error_code = res.status,
  875. error_content = UtilsController.GetErrorCodeCharging(res.status),
  876. msisdn = msisdn.Substring(UtilsController.CountryCode.Length),
  877. href = typeLanguage == UtilsController.Constant.LAOS ? "/Home/LaosIndex" :
  878. typeLanguage == UtilsController.Constant.VIETNAMESE ? "/Home/VietnameseIndex" :
  879. typeLanguage == UtilsController.Constant.ENGLISH ? "/Home/EnglishIndex" : "/Home/Index"
  880. });
  881. }
  882. else
  883. {
  884. return Json(new
  885. {
  886. error_code = res.status,
  887. //error_content = CommonController.ErrorContent(res.status),
  888. error_content = UtilsController.GetErrorCodeCharging(res.status),
  889. msisdn = msisdn.Substring(UtilsController.CountryCode.Length)
  890. });
  891. }
  892. }
  893. else
  894. {
  895. return Json(new
  896. {
  897. error_code = UtilsController.Constant.INVALID_MSISDN,
  898. error_content = Lang.InvalidMsisdn,
  899. });
  900. }
  901. }
  902. catch (Exception ex)
  903. {
  904. log.Error("Exception: ", ex);
  905. return Json(new
  906. {
  907. error_code = UtilsController.Constant.EXCEPTION,
  908. error_content = UtilsController.GetErrorCodeCharging("-10"),
  909. });
  910. }
  911. }
  912. public ActionResult About()
  913. {
  914. ViewBag.Message = "Your application description page.";
  915. return View();
  916. }
  917. public ActionResult AccountProfile()
  918. {
  919. if (CheckAuthToken())
  920. {
  921. ProfileModel model = new ProfileModel();
  922. model.profileDetail = Session["profile"] as UserProfile;
  923. return View("AccountProfileView", model);
  924. }
  925. else
  926. {
  927. Session.Clear();
  928. return Redirect("/Home/Index");
  929. }
  930. }
  931. public ActionResult Profile()
  932. {
  933. if (CheckAuthToken())
  934. {
  935. ProfileModel model = new ProfileModel();
  936. model.profileDetail = Session["profile"] as UserProfile;
  937. return View("ProfileView", model);
  938. }
  939. else
  940. {
  941. Session.Clear();
  942. return Redirect("/Home/Index");
  943. }
  944. }
  945. public ActionResult ChangePass()
  946. {
  947. if (CheckAuthToken())
  948. {
  949. ProfileModel model = new ProfileModel();
  950. model.profileDetail = Session["profile"] as UserProfile;
  951. return View("ChangePassView", model);
  952. }
  953. else
  954. {
  955. Session.Clear();
  956. return Redirect("/Home/Index");
  957. }
  958. }
  959. [ValidateAntiForgeryToken]
  960. public JsonResult UpdateProfile(String fullname, String birthday)
  961. {
  962. try
  963. {
  964. if (CheckAuthToken())
  965. {
  966. UserProfile userProfile = Session["profile"] as UserProfile;
  967. userProfile.fullName = fullname;
  968. userProfile.birthday = birthday;
  969. String rs = UtilsController.SendPost(userProfile, Session.SessionID, UtilsController.WsType.UsersUpdateProfile);
  970. UserActionResult res = new UserActionResult(rs);
  971. if (res.status == UtilsController.Constant.SUCCESS)
  972. {
  973. // update success --> store session
  974. Session["profile"] = userProfile;
  975. return Json(new
  976. {
  977. error_code = res.status,
  978. error_content = res.message,
  979. href = "/Home/Profile"
  980. });
  981. }
  982. else
  983. {
  984. return Json(new
  985. {
  986. error_code = res.status,
  987. error_content = UtilsController.GetErrorCodeCharging(res.status),
  988. });
  989. }
  990. }
  991. else
  992. {
  993. Session.Clear();
  994. return Json(new
  995. {
  996. error_code = UtilsController.Constant.EXCEPTION,
  997. error_content = UtilsController.GetErrorCodeCharging("-10"),
  998. });
  999. }
  1000. }
  1001. catch (Exception ex)
  1002. {
  1003. return Json(new
  1004. {
  1005. error_code = UtilsController.Constant.EXCEPTION,
  1006. error_content = UtilsController.GetErrorCodeCharging("-10"),
  1007. });
  1008. }
  1009. }
  1010. [ValidateAntiForgeryToken]
  1011. public JsonResult UpdatePass(String oldPassword, String password)
  1012. {
  1013. try
  1014. {
  1015. if (CheckAuthToken())
  1016. {
  1017. UserInfoRequest userRequest = new UserInfoRequest();
  1018. userRequest.users = Session["msisdn"] as string;
  1019. userRequest.passnew = password;
  1020. userRequest.pass = oldPassword;
  1021. userRequest.command = "CHANGEPASS";
  1022. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister);
  1023. UserActionResult res = new UserActionResult(rs);
  1024. if (res.status == UtilsController.Constant.SUCCESS)
  1025. {
  1026. // update success --> store session
  1027. return Json(new
  1028. {
  1029. error_code = res.status,
  1030. error_content = res.message,
  1031. href = "/Home/Profile"
  1032. });
  1033. }
  1034. else
  1035. {
  1036. return Json(new
  1037. {
  1038. error_code = res.status,
  1039. error_content = UtilsController.GetErrorCodeCharging(res.status),
  1040. });
  1041. }
  1042. }
  1043. else
  1044. {
  1045. Session.Clear();
  1046. return Json(new
  1047. {
  1048. error_code = UtilsController.Constant.EXCEPTION,
  1049. error_content = UtilsController.GetErrorCodeCharging("-10"),
  1050. });
  1051. }
  1052. }
  1053. catch (Exception ex)
  1054. {
  1055. return Json(new
  1056. {
  1057. error_code = UtilsController.Constant.EXCEPTION,
  1058. error_content = UtilsController.GetErrorCodeCharging("-10"),
  1059. });
  1060. }
  1061. }
  1062. [ValidateAntiForgeryToken]
  1063. public JsonResult ResetPassword(String phoneNumber)
  1064. {
  1065. //if (CheckAuthToken())
  1066. //{
  1067. String msisdn = UtilsController.validateMsisdn(phoneNumber);
  1068. if (msisdn != "")
  1069. {
  1070. UserInfoRequest userRequest = new UserInfoRequest();
  1071. userRequest.users = msisdn;
  1072. userRequest.msisdn = msisdn;
  1073. userRequest.command = "RESETPASS";
  1074. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister);
  1075. UserActionResult res = new UserActionResult(rs);
  1076. if (res.status == UtilsController.Constant.SUCCESS)
  1077. {
  1078. // update success --> store session
  1079. return Json(new
  1080. {
  1081. error_code = res.status,
  1082. error_content = UtilsController.GetErrorCodeCharging(res.status),
  1083. //href = "/Home/Profile"
  1084. });
  1085. }
  1086. else
  1087. {
  1088. return Json(new
  1089. {
  1090. error_code = res.status,
  1091. error_content = UtilsController.GetErrorCodeCharging(res.status),
  1092. });
  1093. }
  1094. }
  1095. else
  1096. {
  1097. return Json(new
  1098. {
  1099. error_code = UtilsController.Constant.INVALID_MSISDN,
  1100. error_content = Lang.InvalidMsisdn,
  1101. });
  1102. }
  1103. }
  1104. [ValidateAntiForgeryToken]
  1105. public JsonResult BuyCourse(String courseId, String phone, int courseChoose, String otpConfirm)
  1106. {
  1107. try
  1108. {
  1109. if (CheckAuthToken())
  1110. {
  1111. if (otpConfirm == null)
  1112. {
  1113. UserRequest userRequest = new UserRequest();
  1114. userRequest.users = phone;
  1115. userRequest.courseId = courseId;
  1116. userRequest.codeBuy = courseChoose == 7 ? "EDU_CHARGE_50" : "EDU_CHARGE_200";
  1117. userRequest.requestId = "-1";
  1118. userRequest.otp = "-1";
  1119. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.buyCourse);
  1120. UserActionResult res = new UserActionResult(rs);
  1121. System.Diagnostics.Debug.WriteLine(rs);
  1122. if (res.status == UtilsController.Constant.WAITING_OTP)
  1123. //if (res.status == UtilsController.Constant.SUCCESS) // for test
  1124. {
  1125. Charging charging = new Charging(rs);
  1126. Session["charging"] = charging;
  1127. Session["CHARGE_ACTION"] = UtilsController.Constant.BUY_COURSE;
  1128. Session["CHARGE_DATA"] = userRequest;
  1129. }
  1130. return Json(new
  1131. {
  1132. error_code = res.status,
  1133. error_content = UtilsController.GetErrorCodeCharging(res.status),
  1134. });
  1135. }
  1136. else
  1137. {
  1138. String msisdn = UtilsController.validateMsisdn(phone);
  1139. if (msisdn != "")
  1140. {
  1141. UserRequest userRequest = new UserRequest();
  1142. userRequest.users = phone;
  1143. userRequest.courseId = courseId;
  1144. userRequest.codeBuy = courseChoose == 7 ? "EDU_CHARGE_50" : "EDU_CHARGE_200";
  1145. // get requestId on buying course
  1146. Charging charging = Session["charging"] as Charging;
  1147. userRequest.requestId = charging.requestId;
  1148. userRequest.otp = otpConfirm.ToString();
  1149. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.buyCourse);
  1150. UserActionResult res = new UserActionResult(rs);
  1151. System.Diagnostics.Debug.WriteLine(rs);
  1152. return Json(new
  1153. {
  1154. error_code = res.status,
  1155. error_content = UtilsController.GetErrorCodeCharging(res.status),
  1156. });
  1157. }
  1158. else
  1159. {
  1160. return Json(new
  1161. {
  1162. error_code = UtilsController.Constant.INVALID_MSISDN,
  1163. error_content = Lang.InvalidMsisdn,
  1164. });
  1165. }
  1166. }
  1167. }
  1168. else
  1169. {
  1170. Session.Clear();
  1171. return Json(new
  1172. {
  1173. error_code = UtilsController.Constant.EXCEPTION,
  1174. error_content = UtilsController.GetErrorCodeCharging("-10"),
  1175. });
  1176. }
  1177. }
  1178. catch (Exception ex)
  1179. {
  1180. return Json(new
  1181. {
  1182. error_code = UtilsController.Constant.EXCEPTION,
  1183. error_content = UtilsController.GetErrorCodeCharging("-10"),
  1184. });
  1185. }
  1186. }
  1187. public ActionResult GetRanking()
  1188. {
  1189. if (CheckAuthToken())
  1190. {
  1191. RankingModel model = new RankingModel();
  1192. UserInfoRequest user = new UserInfoRequest();
  1193. user.users = Session["msisdn"] as string;
  1194. user.msisdn = Session["msisdn"] as String;
  1195. String rs = UtilsController.SendPost(user, Session.SessionID, UtilsController.WsType.GetRanking);
  1196. System.Diagnostics.Debug.WriteLine("rs: " + rs);
  1197. UserActionResult res = new UserActionResult(rs);
  1198. if (res.status == UtilsController.Constant.SUCCESS)
  1199. {
  1200. Ranking ranking = new Ranking(rs);
  1201. model.ranking = ranking;
  1202. // get current ranking
  1203. for (int i = 0; i < ranking.listRanking.Count; i++)
  1204. {
  1205. if (ranking.listRanking[i].users == Session["msisdn"] as string)
  1206. {
  1207. model.currentRanking = ranking.listRanking[i];
  1208. }
  1209. }
  1210. return PartialView("_ModalRanking", model);
  1211. }
  1212. else
  1213. {
  1214. return Redirect("/Common/Error");
  1215. }
  1216. }
  1217. else
  1218. {
  1219. Session.Clear();
  1220. return Redirect("/Home/Index");
  1221. }
  1222. }
  1223. private void CreateAuthToken()
  1224. {
  1225. // create session authen
  1226. SessionIDManager manager = new SessionIDManager();
  1227. string newSessionId = manager.CreateSessionID(System.Web.HttpContext.Current);
  1228. Response.Cookies["AuthToken"].Value = newSessionId;
  1229. Session["AuthToken"] = newSessionId;
  1230. }
  1231. private bool CheckAuthToken()
  1232. {
  1233. if (Session["AuthToken"] != null && Request.Cookies["AuthToken"] != null)
  1234. {
  1235. if (!Session["AuthToken"].ToString().Equals(Request.Cookies["AuthToken"].Value))
  1236. {
  1237. return false;
  1238. }
  1239. else
  1240. {
  1241. return true;
  1242. }
  1243. }
  1244. else
  1245. {
  1246. return false;
  1247. }
  1248. }
  1249. public RedirectResult Logout()
  1250. {
  1251. Session.Clear();
  1252. return Redirect("/Home/Index");
  1253. }
  1254. }
  1255. }