Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.92 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Microsoft.AspNet.Identity;
  7. using Microsoft.Owin.Security;
  8. using Vroom.Web.Models;
  9. using Vroom.Application.Users;
  10. using Vroom.Common.Infrastructure;
  11. using System.Web.Security;
  12. using Omu.ValueInjecter;
  13. using Vroom.Common.Helpers;
  14. using Vroom.Web.Infrastructure;
  15. using Microsoft.AspNet.Identity.Owin;
  16. using Facebook;
  17. using Vroom.Common.Classes;
  18. using Vroom.Domain.Entities;
  19. using Vroom.Application.Email;
  20. using Vroom.Application.Email.StoredMails;
  21. using Vroom.Web.Core.Classes;
  22. using Vroom.Application.Email.Models;
  23.  
  24. namespace Vroom.Web.Controllers
  25. {
  26. [Authorize]
  27. public class AccountController : VroomBaseController
  28. {
  29. #region Members
  30.  
  31. public UserManager<ApplicationUser> UserManager { get; private set; }
  32.  
  33. #endregion
  34.  
  35. #region Properties
  36.  
  37. private readonly IUserService _userService;
  38.  
  39. #endregion
  40.  
  41. #region Constructor
  42.  
  43. public AccountController(IUserService userService)
  44. {
  45. _userService = userService;
  46. }
  47. #endregion
  48.  
  49. #region Methods
  50.  
  51. [HttpGet]
  52. [AllowAnonymous]
  53. public ActionResult Login(string returnUrl)
  54. {
  55. if (string.IsNullOrEmpty(returnUrl) && Request.UrlReferrer != null)
  56. returnUrl = Request.UrlReferrer.PathAndQuery;
  57.  
  58. ViewBag.PageSectionTealium = CoreHelper.GetEnumDescription(PageSectionTealium.MijnVroom);
  59. ViewBag.PageTypeTealium = CoreHelper.GetEnumDescription(PageTypeTealium.Aanmelden);
  60.  
  61. if (!string.IsNullOrEmpty(returnUrl))
  62. ViewBag.ReturnUrl = returnUrl;
  63. return View();
  64. }
  65.  
  66. [HttpPost]
  67. [AllowAnonymous]
  68. public ActionResult Login(LoginViewModel model, string returnUrl)
  69. {
  70. if (ModelState.IsValid)
  71. {
  72. var loggedInPerson = new FrontendUserDTO();
  73. var passwordHash = Cryptography.EncryptToMd5(model.Password);
  74. var user = _userService.GetByEmail(model.Email);
  75.  
  76. if (string.IsNullOrWhiteSpace(user?.Password) || !user.Password.Equals(passwordHash) || !user.IsActive)
  77. {
  78. if (Request.IsAjaxRequest())
  79. return FailAjaxLogin();
  80. SetupErrorLoginForNotAjaxCall(returnUrl);
  81. return View();
  82. }
  83.  
  84. SetupForLogedUser(model, user, loggedInPerson);
  85.  
  86. if (Request.IsAjaxRequest())
  87. return Json(new { success = true, userId = loggedInPerson.Id });
  88.  
  89. if (returnUrl == null)
  90. return RedirectToAction("Index", "Home");
  91.  
  92. return Redirect(returnUrl);
  93. }
  94.  
  95. Identity.Current.SignOut();
  96. if (Request.IsAjaxRequest())
  97. FailAjaxLogin();
  98. // If we got this far, something failed, redisplay form
  99. return View();
  100. }
  101.  
  102. [AllowAnonymous]
  103. [HttpPost]
  104. public ActionResult ForgotPassword(string email)
  105. {
  106. var user = _userService.GetByEmail(email);
  107. if (user == null)
  108. {
  109. return Json(new { success = false, error = Resources.Login.ForgotPasswordError });
  110. }
  111. user.UserToken = CommonHelpers.GenerateUniqueToken();
  112. user.TokenDate = DateTime.Now;
  113. _userService.Update(user);
  114. var mailInfo = new StoredMailsInfo
  115. {
  116. Email = user.Email,
  117. MessagentId = user.MessagentUserId,
  118. UserId = user.Id,
  119. Type = MailType.ForgotPasswordMail
  120. };
  121.  
  122. //send mail - (when generating the reset password link, add returnUrl param to the querystring => returnUrl = Request.UrlReferrer.PathAndQuery)
  123. MailCore.SendForgotPasswordMail(user.MessagentUserId ?? 0, user.Firstname, user.UserToken, mailInfo);
  124.  
  125. if (Request.IsAjaxRequest())
  126. {
  127. return Json(new { success = true, userMail = email });
  128. }
  129. return View();
  130. }
  131.  
  132. [AllowAnonymous]
  133. [HttpGet]
  134. public ActionResult InputPassword(string id)
  135. {
  136. var user = _userService.GetByUserToken(id);
  137. if (user == null || user.TokenDate == null || (DateTime.Now - user.TokenDate).Value.TotalHours > 48)
  138. return RedirectToAction("TokenException", "Account");
  139. ViewBag.UserFirstName = user.Firstname ?? string.Empty;
  140.  
  141. //Return View("~/Views/Account/TokenException.cshtml");
  142. return View();
  143. }
  144.  
  145. [AllowAnonymous]
  146. [HttpGet]
  147. public ActionResult TokenException()
  148. {
  149. return View();
  150. }
  151.  
  152. [AllowAnonymous]
  153. [HttpGet]
  154. public ActionResult InputPasswordSuccessful()
  155. {
  156. return View();
  157. }
  158.  
  159. [AllowAnonymous]
  160. [HttpPost]
  161. public ActionResult InputPassword(string id, InputPasswordViewModel inputPassword, string returnUrl)
  162. {
  163. inputPassword.NewPassword = _userService.DecodeUserPassword(inputPassword.NewPasswordHashed);
  164. inputPassword.ConfirmPassword = _userService.DecodeUserPassword(inputPassword.ConfirmPasswordHashed);
  165.  
  166. if (!string.IsNullOrEmpty(id))
  167. {
  168. var user = _userService.GetByUserToken(id);
  169. user.Password = Cryptography.EncryptToMd5(inputPassword.NewPassword);
  170. user.IsApproved = true;
  171. user.UserToken = null;
  172. user.TokenDate = null;
  173. _userService.Update(user);
  174. }
  175.  
  176. return RedirectToAction("InputPasswordSuccessful", "Account");
  177. //return View("~/Views/Account/InputPasswordSuccessful.cshtml");
  178. }
  179.  
  180. [AllowAnonymous]
  181. [HttpGet]
  182. public ActionResult SignOut(string returnUrl)
  183. {
  184. Identity.Current.SignOut();
  185. return RedirectToAction("Index", "Home", new { lang = RouteHelper.GetRouteLanguage() });
  186. }
  187.  
  188. [AllowAnonymous]
  189. public ActionResult AccountActivation(string id)
  190. {
  191. if (string.IsNullOrEmpty(id))
  192. return HttpNotFound();
  193. var user = _userService.GetByUserToken(id);
  194. if (user == null) return HttpNotFound();
  195.  
  196. if ((user.TokenDate?.AddDays(2) < DateTime.Now) || user.TokenDate == null)
  197. {
  198. ViewBag.AccountActivation = AccountActivationStatus.TokenExpired;
  199. return View();
  200. }
  201. if (user.IsApproved == true)
  202. ViewBag.AccountActivation = AccountActivationStatus.AccountAlreadyActivated;
  203. else
  204. {
  205. user.IsApproved = true;
  206. _userService.Update(user);
  207. ViewBag.AccountActivation = AccountActivationStatus.AccountSuccesfullyActivated;
  208. }
  209. var loggedInPerson = new FrontendUserDTO();
  210. loggedInPerson.InjectFrom(user);
  211. Identity.Current.User = loggedInPerson;
  212. ViewBag.ActivationReturnURL = Url.Action("Index", "Home", new { lang = RouteHelper.GetRouteLanguage() });
  213. return View();
  214. }
  215.  
  216. [AllowAnonymous]
  217. public ActionResult Register(string returnUrl)
  218. {
  219. ViewBag.ReturnUrl = returnUrl;
  220. return View();
  221. }
  222.  
  223. [HttpPost]
  224. [AllowAnonymous]
  225. public ActionResult Register(RegisterViewModel model, string returnUrl)
  226. {
  227. if (ModelState.IsValid)
  228. {
  229. var passwordHash = Cryptography.EncryptToMd5(model.Password);
  230. var personExists = _userService.GetByEmail(model.Email) != null;
  231. if (personExists)
  232. {
  233. if (Request.IsAjaxRequest())
  234. return Json(new { success = false, error = Resources.Register.RegisterFailed });
  235. ModelState.Clear();
  236. ModelState.AddModelError("", Resources.Register.RegisterFailed);
  237. model.Email = string.Empty;
  238. return View(model);
  239. }
  240. FrontendUserDTO registerPerson = new FrontendUserDTO();
  241. registerPerson.Email = model.Email;
  242. registerPerson.Password = passwordHash;
  243. if (model.PhoneNumber != null)
  244. registerPerson.Phone = model.CountryCode + CommonHelpers.StripPhoneNumber(model.PhoneNumber);
  245. registerPerson.IsApproved = false;
  246. registerPerson.IsActive = true;
  247. registerPerson.Language = RouteHelper.GetRouteLanguage().ToLower();
  248. registerPerson.DateCreated = DateTime.Now;
  249. registerPerson.UserToken = CommonHelpers.GenerateUniqueToken();
  250. registerPerson.TokenDate = DateTime.Now;
  251.  
  252. int messagentId = CreateMessagentUserByFrontendUserModel(model, registerPerson);
  253. if (messagentId > 0)
  254. {
  255. registerPerson.MessagentUserId = messagentId;
  256. }
  257. var user = new User();
  258. user.InjectFrom(registerPerson);
  259. user = _userService.Add(user);
  260. registerPerson.Id = user.Id;
  261.  
  262. var mailInfo = new StoredMailsInfo
  263. {
  264. Email = registerPerson.Email,
  265. MessagentId = messagentId,
  266. UserId = registerPerson.Id,
  267. Type = MailType.UserWelcomeMail
  268. };
  269. MailCore.SendWelcomeMail(messagentId, registerPerson.Firstname, registerPerson.Lastname,
  270. registerPerson.UserToken, mailInfo);
  271.  
  272. FormsAuthentication.SetAuthCookie(model.Email, false);
  273. CreatePersistentCookie(registerPerson, false);
  274. Identity.CreateIdentity(registerPerson);
  275. TempData["RegisterThankYou"] = true;
  276. if (Request.IsAjaxRequest())
  277. {
  278. return Json(new { success = true });
  279. }
  280. if (string.IsNullOrEmpty(returnUrl))
  281. return RedirectToAction("Index", "Home");
  282. return Redirect(returnUrl);
  283. }
  284.  
  285. if (Request.IsAjaxRequest())
  286. return Json(new { success = false, error = Resources.Register.RegisterFailed });
  287.  
  288. // If we got this far, something failed, redisplay form
  289. return View(model);
  290. }
  291.  
  292. public ActionResult SendRegisterEmailAgain()
  293. {
  294. var sendSuccesMail = false;
  295. if (Identity.Current.User.Email != null)
  296. {
  297. var mailInfo = new StoredMailsInfo
  298. {
  299. Email = Identity.Current.User.Email,
  300. MessagentId = Identity.Current.User.MessagentUserId,
  301. UserId = Identity.Current.User.Id,
  302. Type = MailType.UserWelcomeMail
  303. };
  304. var user = _userService.GetByID(Identity.Current.User.Id);
  305. Identity.Current.User.UserToken = user.UserToken = CommonHelpers.GenerateUniqueToken();
  306. user.TokenDate = DateTime.Now;
  307. _userService.Update(user);
  308. sendSuccesMail = MailCore.SendWelcomeMail(Identity.Current.User.MessagentUserId ?? 0, Identity.Current.User.Firstname, Identity.Current.User.Lastname, Identity.Current.User.UserToken, mailInfo);
  309. }
  310. if (!Request.IsAjaxRequest())
  311. return RedirectToAction("Index", "Home");
  312. return Json(sendSuccesMail ? new { success = true } : new { success = false }, JsonRequestBehavior.AllowGet);
  313. }
  314. public ActionResult VerifyAccount()
  315. {
  316. return View("~/Views/Shared/VerifyAccount.cshtml");
  317. }
  318. public ActionResult SendVerificationEmail()
  319. {
  320. var user = Identity.Current.User;
  321. var email = user.Email;
  322. var token = user.UserToken;
  323. //send email
  324. if (Request.IsAjaxRequest())
  325. return Json(new { success = true });
  326. return RedirectToAction("Index", "Home");
  327. }
  328. public ExternalLoginUser RetrieveExternalInformation(ExternalLoginInfo loginInfo)
  329. {
  330. ExternalLoginUser user = new ExternalLoginUser();
  331.  
  332. if (loginInfo != null)
  333. {
  334. if (loginInfo.Login != null)
  335. if (loginInfo.Login.LoginProvider == "Facebook")
  336. user.FacebookID = loginInfo.Login.ProviderKey;
  337. else user.GooglePlusID = loginInfo.Login.ProviderKey;
  338.  
  339. if (loginInfo.ExternalIdentity != null && loginInfo.ExternalIdentity.Claims != null)
  340. {
  341. if (loginInfo.Login != null && loginInfo.Login.LoginProvider == "Facebook")
  342. {
  343. var identity = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
  344. var accessToken = identity.FindFirstValue("FacebookAccessToken");
  345. var fb = new FacebookClient(accessToken);
  346. dynamic myInfo = fb.Get("/me?fields=email,first_name,last_name"); // specify the email field
  347. if (myInfo != null)
  348. {
  349. if (!string.IsNullOrEmpty(myInfo.email))
  350. user.Email = myInfo.email;
  351.  
  352. if (!string.IsNullOrEmpty(myInfo.first_name))
  353. user.Firstname = myInfo.first_name;
  354.  
  355. if (!string.IsNullOrEmpty(myInfo.last_name))
  356. user.Lastname = myInfo.last_name;
  357.  
  358. }
  359. }
  360. else
  361. {
  362. if (loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.FirstName) != null && !string.IsNullOrEmpty(loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.FirstName).Value))
  363. user.Firstname = loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.FirstName).Value;
  364.  
  365. if (loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.LastName) != null && !string.IsNullOrEmpty(loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.LastName).Value))
  366. user.Lastname = loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.LastName).Value;
  367.  
  368. if (loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.Email) != null && !string.IsNullOrEmpty(loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.Email).Value))
  369. user.Email = loginInfo.ExternalIdentity.Claims.ElementAt((int)GoogleClaims.Email).Value;
  370. }
  371. }
  372. }
  373. return user;
  374. }
  375.  
  376. [HttpPost]
  377. [AllowAnonymous]
  378. public ActionResult ExternalLogin(string provider, string returnUrl)
  379. {
  380. //if(Identity.Current.User!=null)
  381. // return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel(true, 0, null));
  382. Identity.Current = null;
  383. //ControllerContext.HttpContext.Session.Remove("vroomIdentity");
  384. //ControllerContext.HttpContext.Session.RemoveAll();
  385. // Request a redirect to the external login provider RetrieveExternalInformation
  386. return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }, Request.Url.Scheme));
  387. }
  388.  
  389. [AllowAnonymous]
  390. public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
  391. {
  392. var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
  393. var externalUser = RetrieveExternalInformation(loginInfo);
  394. if (loginInfo == null || externalUser.Email == null)
  395. {
  396. return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel(false, 0, returnUrl));
  397. }
  398.  
  399. User dbUser = new User();
  400. dbUser.InjectFrom(externalUser);
  401. //if (dbUser.FacebookID == null && externalUser.FacebookId != null)
  402. // dbUser.FacebookID = externalUser.FacebookId;
  403. //if (dbUser.GooglePlusID == null && externalUser.GooglePlusId != null)
  404. // dbUser.FacebookID = externalUser.FacebookId;
  405. var user = _userService.GetUserbyExternalId(dbUser, loginInfo.Login.LoginProvider.ToLower());
  406.  
  407. if (user == null)
  408. {
  409. dbUser.IsActive = true;
  410. dbUser.IsApproved = true;
  411. dbUser.Language = RouteHelper.GetRouteLanguage().ToLower();
  412. dbUser.DateCreated = DateTime.Now;
  413. //Implement Mailing method
  414. dbUser.UserToken = CommonHelpers.GenerateUniqueToken();
  415. dbUser.TokenDate = DateTime.Now;
  416.  
  417. int messagentId = CreateMessagentUserByUserModel(dbUser);
  418. if (messagentId > 0)
  419. {
  420. dbUser.MessagentUserId = messagentId;
  421. }
  422. _userService.Add(dbUser);
  423. }
  424. else
  425. {
  426. dbUser.InjectFrom(user);
  427. if (dbUser.FacebookID == null && externalUser.FacebookID != null)
  428. dbUser.FacebookID = externalUser.FacebookID;
  429. if (dbUser.GooglePlusID == null && externalUser.GooglePlusID != null)
  430. dbUser.GooglePlusID = externalUser.GooglePlusID;
  431. if (dbUser.Firstname == null)
  432. {
  433. dbUser.Firstname = externalUser.Firstname;
  434. }
  435. if (dbUser.Lastname == null)
  436. {
  437. dbUser.Lastname = externalUser.Lastname;
  438. }
  439. _userService.Update(dbUser);
  440. }
  441.  
  442. FrontendUserDTO loggedInPerson = new FrontendUserDTO();
  443. loggedInPerson.InjectFrom(dbUser);
  444.  
  445. FormsAuthentication.SetAuthCookie(externalUser.Email, false);
  446. CreatePersistentCookie(loggedInPerson, false);
  447. Identity.CreateIdentity(loggedInPerson);
  448.  
  449. return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel(true, loggedInPerson.Id, returnUrl));
  450. }
  451. public ActionResult ExternalLoginFailure()
  452. {
  453. return View();
  454. }
  455.  
  456. #endregion
  457.  
  458. #region Private Methods
  459.  
  460. private void CreatePersistentCookie(FrontendUserDTO user, bool createPersistentCookie)
  461. {
  462. var now = DateTime.UtcNow.ToLocalTime();
  463.  
  464. var ticket = new FormsAuthenticationTicket(
  465. 1 /*version*/,
  466. user.Email,
  467. now,
  468. createPersistentCookie ? now.AddDays(14) : now.Add(FormsAuthentication.Timeout),
  469. createPersistentCookie,
  470. user.Email,
  471. FormsAuthentication.FormsCookiePath);
  472.  
  473. var encryptedTicket = FormsAuthentication.Encrypt(ticket);
  474.  
  475. var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) { HttpOnly = true };
  476. if (ticket.IsPersistent)
  477. {
  478. cookie.Expires = ticket.Expiration;
  479. }
  480. cookie.Secure = FormsAuthentication.RequireSSL;
  481. cookie.Path = FormsAuthentication.FormsCookiePath;
  482. if (FormsAuthentication.CookieDomain != null)
  483. {
  484. cookie.Domain = FormsAuthentication.CookieDomain;
  485. }
  486.  
  487. HttpContext.Response.Cookies.Add(cookie);
  488. }
  489. protected override void Dispose(bool disposing)
  490. {
  491. if (disposing && UserManager != null)
  492. {
  493. UserManager.Dispose();
  494. UserManager = null;
  495. }
  496. base.Dispose(disposing);
  497. }
  498. private void SetupErrorLoginForNotAjaxCall(string returnUrl)
  499. {
  500. ViewBag.IsInvalidSignIn = true;
  501. ModelState.Clear();
  502. ModelState.AddModelError("", Resources.Login.LoginFailed);
  503. if (!string.IsNullOrEmpty(returnUrl))
  504. ViewBag.ReturnUrl = returnUrl;
  505. }
  506. // Used for XSRF protection when adding external logins
  507. private const string XsrfKey = "XsrfId";
  508. private IAuthenticationManager AuthenticationManager
  509. {
  510. get
  511. {
  512. return HttpContext.GetOwinContext().Authentication;
  513. }
  514. }
  515. private async Task SignInAsync(ApplicationUser user, bool isPersistent)
  516. {
  517. AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
  518. var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
  519. AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
  520. }
  521. private void AddErrors(IdentityResult result)
  522. {
  523. foreach (var error in result.Errors)
  524. {
  525. ModelState.AddModelError("", error);
  526. }
  527. }
  528. private bool HasPassword()
  529. {
  530. var user = UserManager.FindById(User.Identity.GetUserId());
  531. if (user != null)
  532. {
  533. return user.PasswordHash != null;
  534. }
  535. return false;
  536. }
  537. public enum ManageMessageId
  538. {
  539. ChangePasswordSuccess,
  540. SetPasswordSuccess,
  541. RemoveLoginSuccess,
  542. Error
  543. }
  544. private ActionResult RedirectToLocal(string returnUrl)
  545. {
  546. if (Url.IsLocalUrl(returnUrl))
  547. {
  548. return Redirect(returnUrl);
  549. }
  550. else
  551. {
  552. return RedirectToAction("Index", "Home");
  553. }
  554. }
  555. private class ChallengeResult : HttpUnauthorizedResult
  556. {
  557. public ChallengeResult(string provider, string redirectUri) : this(provider, redirectUri, null)
  558. {
  559. }
  560.  
  561. public ChallengeResult(string provider, string redirectUri, string userId)
  562. {
  563. LoginProvider = provider;
  564. RedirectUri = redirectUri;
  565. UserId = userId;
  566. }
  567.  
  568. public string LoginProvider { get; set; }
  569. public string RedirectUri { get; set; }
  570. public string UserId { get; set; }
  571.  
  572. public override void ExecuteResult(ControllerContext context)
  573. {
  574. context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
  575. var properties = new AuthenticationProperties { RedirectUri = RedirectUri };
  576. if (UserId != null)
  577. {
  578. properties.Dictionary[XsrfKey] = UserId;
  579. }
  580. context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
  581. }
  582. }
  583. private static int CreateMessagentUserByUserModel(User dbUser)
  584. {
  585. var userProfileData = new ProfileData();
  586. userProfileData.FirstName = dbUser.Firstname;
  587. userProfileData.LastName = dbUser.Lastname;
  588. userProfileData.Email = dbUser.Email;
  589. userProfileData.Language = dbUser.Language ?? RouteHelper.GetRouteLanguage();
  590.  
  591. var messagentId = MessagentService.CreateMesagentUserId(userProfileData, MessagentListId.Users);
  592. return messagentId;
  593. }
  594. private static int CreateMessagentUserByFrontendUserModel(RegisterViewModel model, FrontendUserDTO registerPerson)
  595. {
  596. var userProfileData = new ProfileData();
  597. userProfileData.FirstName = registerPerson.Firstname;
  598. userProfileData.LastName = registerPerson.Lastname;
  599. userProfileData.Email = model.Email;
  600. userProfileData.Language = registerPerson.Language ?? RouteHelper.GetRouteLanguage();
  601.  
  602. var messagentId = MessagentService.CreateMesagentUserId(userProfileData, MessagentListId.Users);
  603. return messagentId;
  604. }
  605. private void SetupForLogedUser(LoginViewModel model, User user, FrontendUserDTO loggedInPerson)
  606. {
  607. user.UserToken = null;
  608. user.TokenDate = null;
  609. _userService.Update(user);
  610. loggedInPerson.InjectFrom(user);
  611. FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
  612. CreatePersistentCookie(loggedInPerson, model.RememberMe);
  613. Identity.CreateIdentity(loggedInPerson);
  614. }
  615. private ActionResult FailAjaxLogin()
  616. {
  617. return Json(new { success = false, error = Resources.Login.LoginFailed });
  618. }
  619. }
  620. #endregion
  621. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement