private void SignIn(CarsSaleUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie)); }
public ActionResult Registry(CreateAccountViewModel account) { if (!ModelState.IsValid) { ModelState.AddModelError("", "The registered form is invalid! Please try again"); return(View()); } if (UserManager.IsEmailExists(account.Email)) { ModelState.AddModelError("Email", $"Email '{account.Email}' arleady registered"); return(View()); } if (UserManager.IsLoginExists(account.Login)) { ModelState.AddModelError("Email", $"Login '{account.Login}' arleady registered"); return(View()); } if (UserManager.IsPhoneExists(FormatPhone(account.Phone))) { ModelState.AddModelError("Email", $"Phone '{account.Phone}' arleady registered"); return(View()); } var user = new CarsSaleUser { UserName = account.Login, PhoneNumber = account.Phone, Email = account.Email, Claims = { new CarsSaleClaim { ClaimType = ClaimTypes.DateOfBirth, ClaimValue = account.Birthday.ToLongDateString() } }, FullName = account.Name, Birthday = account.Birthday }; var result = UserManager.Create(user, account.Password); if (result.Succeeded) { SignIn(user, false); return(RedirectToAction("Index", "Home")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } return(View()); }
public Advertisement(ADVERTISEMENT entity = null) { if (entity == null) { return; } Id = entity.ID; IsActive = entity.IS_ACTIVE; ExpirationDate = entity.EXPIRATION_DATE; CreatedDate = entity.CREATED_DATE; Vehicl = new Vehicl(entity.VEHICL); Region = new Region(entity.REGION); ImagePath = entity.IMAGE_PATH; Currency = new Currency(entity.CURRENCY); Price = entity.PRICE; User = new CarsSaleUser { Email = entity.User?.Email, UserName = entity.User?.UserName, PhoneNumber = entity.User?.PhoneNumber, FullName = entity.User?.FullName }; }