public ActionResult ConfirmEmail(Guid guid) { { BusinessLayerResult <User> res = us.ConfirmEmail(guid); if (res.Errors.Count > 0) { ErrorViewModel errorNotifyObj = new ErrorViewModel() { Title = "Geçersiz İşlem", Items = res.Errors }; return(View("Error", errorNotifyObj)); } OkViewModel okNotifyObj = new OkViewModel() { Title = "Hesap Aktifleştirildi", RedirectingUrl = "/Account/Login" }; return(View("Ok", okNotifyObj)); } }
public ActionResult ActivarCuenta(string u, string c, ActivarCuentaViewModel modelo) { ApplicationUser usuario = null; if (u == null || c == null || (usuario = UserManager.FindById(u)) == null || usuario.EmailConfirmed) { return(Redirect("Login")); } if (ModelState.IsValid) { var result = UserManager.ConfirmEmail(u, c); if (result.Succeeded) { result = UserManager.AddPassword(u, modelo.Password); if (result.Succeeded) { return(View("ActivarCuentaConfirmacion")); } else { _controllerHelper.CargarErrores(result.Errors); } } else { _controllerHelper.CargarErrores(result.Errors); } } return(View(modelo)); }
public AuthenticationServiceResponse ConfirmAccount(int userId, string code) { if (!string.IsNullOrEmpty(userId.ToString()) && !string.IsNullOrEmpty(code)) { ApplicationUser user = UserManager.FindById(userId); if (user != null) { string newCode = WebUtility.UrlDecode(code); var result = UserManager.ConfirmEmail(userId, code); if (!result.Succeeded) { return(new AuthenticationServiceResponse() { Success = false, Message = "Licence Experienced" }); } user.EmailConfirmed = true; user.UpdatedDate = DateTime.Now; UserManager.Update(user); return(new AuthenticationServiceResponse() { Success = true, Message = "Successfully" }); } } return(new AuthenticationServiceResponse() { Success = false, Message = "Invalid Code" }); }
public ActionResult ConfirmEmail(string userID, string code) { var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore); var user = manager.FindById(userID); CreateTokenProvider(manager, EMAIL_CONFIRMATION); try { IdentityResult result = manager.ConfirmEmail(userID, code); if (result.Succeeded) { TempData["ConfirmationResponse"] = "You have successfully registered for an account. Please verify your account by clicking on the link sent to you in your e-mail."; return RedirectToAction("Login"); } else { TempData["ConfirmationResponseError"] = "Your validation attempt has failed. We may be experiencing system problems. Please try again later."; return RedirectToAction("Login"); } } catch { TempData["ConfirmationResponseError"] = "Your validation attempt has failed. We may be experiencing system problems. Please try again later."; return RedirectToAction("Login"); } }
public IHttpActionResult Activate(ActivationBindingModel model) { Logger.Info("Activate requested for [User#{0}] with code: {1}.", model.UserId, model.Code); if (!ModelState.IsValid) { Logger.Error("ModelState is invalid."); return(BadRequest(ModelState)); } if (model.UserId == default(int) || string.IsNullOrEmpty(model.Code)) { Logger.Error("UserId is 0 and/or Code is null or empty"); return(BadRequest()); } var result = UserManager.ConfirmEmail(model.UserId, model.Code); if (!result.Succeeded) { Logger.Error("UserManager.ConfirmEmailAsync failed. {0}", String.Join(Environment.NewLine, result.Errors)); } return(Ok(result.Succeeded ? "Ok" : "Error")); }
public async Task <ConfirmationEmailResponseDto> ConfirmEmail(ConfirmEmailDto confirmEmailDto) { var user = await _userManager.Users.FirstOrDefaultAsync(x => x.EmailConfirmationToken == confirmEmailDto.ConfirmationToken); var confirmationEmailResponse = await _userManager.ConfirmEmail(_userStore, user); return(confirmationEmailResponse); }
public string ConfirmEmail(string userConfirmationToken) { if (_userManager.ConfirmEmail(userConfirmationToken)) { var userId = _userManager.GetUserByConfirmationToken(userConfirmationToken).UserId; return(_tokenManager.AssignToken(userId)); } return(null); }
public IHttpActionResult ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(NotFound()); } var result = UserManager.ConfirmEmail(userId, code); return(Ok("ConfirmEmail")); }
public ActionResult ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(View("Error")); } var result = UserManager.ConfirmEmail(userId, code); return(View(result.Succeeded ? nameof(ConfirmEmail) : "Error")); }
public dynamic ConfirmEmail(string userId, string code) { try { var result = UserManager.ConfirmEmail(userId, code); return(result); } catch (Exception) { throw; } }
public void CanGetEmailConfirmed() { var user = IdentityUserMother.BasicUser(); UserManager.Create(user); var token = UserManager.GenerateEmailConfirmationToken(user.Id); var result = UserManager.ConfirmEmail(user.Id, token); result.Succeeded.ShouldBe(true); UserManager.IsEmailConfirmed(user.Id).ShouldBe(true); }
public HttpResponseMessage ConfirmEmail([FromUri] string userid, string token) { UserManager.ConfirmEmail(userid, token.Replace("%2b", "+")); return(Request.CreateResponse(HttpStatusCode.OK)); //if (rs.Succeeded) //{ // return Request.CreateResponse(HttpStatusCode.OK, "Confirmation Sucessful"); //} //else //{ // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unsucessful"); //} }
public IHttpActionResult ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(Redirect(CORSConfig.returnOrigin + "/emailconfirm/error")); } var result = UserManager.ConfirmEmail(userId, code); if (result.Succeeded) { return(Redirect(CORSConfig.returnOrigin + "/emailconfirm")); } return(Redirect(CORSConfig.returnOrigin + "/emailconfirm/error")); }
public ActionResult RegistrationConfirm() { string token = Request.QueryString["token"]; string id = Request.QueryString["id"]; IdentityResult result = userManager.ConfirmEmail(id, token); if (result.Succeeded) { return(RedirectToAction("Information", "Info", new { text = "AccountActivated" })); } else { return(RedirectToAction("Information", "Info", new { text = "Error" })); } }
protected void Page_Load(object sender, EventArgs e) { string code = IdentityHelper.GetCodeFromRequest(Request); string userId = IdentityHelper.GetUserIdFromRequest(Request); if (code != null && userId != null) { var result = UserManager.ConfirmEmail(userId, code); if (result.Succeeded) { successPanel.Visible = true; return; } } successPanel.Visible = false; errorPanel.Visible = true; }
public ActionResult ConfirmEmail(string userId, string token) { if (String.IsNullOrEmpty(userId) || string.IsNullOrEmpty(token)) { return(View()); } var result = UserManager.ConfirmEmail(userId, token); if (result.Succeeded) { UserManager.AddToRole(userId, RoleConstant.RoleUser); return(Redirect("~/")); } return(View()); }
public ActionResult ConfirmEmail(string userId, string code) { var provider = new DpapiDataProtectionProvider("Sample"); UserManager.UserTokenProvider = new DataProtectorTokenProvider <MyUser>( provider.Create("EmailConfirmation")); IdentityResult result = UserManager.ConfirmEmail(userId, code); if (result.Succeeded) { return(RedirectToAction("Index", "Account")); } else { ModelState.AddModelError("", "Что-то пошло не так"); } return(RedirectToAction("Index", "Account")); }
public ActionResult ConfirmEmail(string userID, string code) { var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore); var user = manager.FindById(userID); CreateTokenProvider(manager, EMAIL_CONFIRMATION); try { IdentityResult result = manager.ConfirmEmail(userID, code); if (result.Succeeded) ViewBag.Message = "You are now registered!"; } catch { ViewBag.Message = "Validation attempt failed!"; } return View(); }
public ActionResult ShowAccountConfirmationCode(string email, string userId, string code, string action) { if (action == "test") { var result = UserManager.ConfirmEmail(userId, code); //todo } else { var usr = UserManager.FindByEmail(email); if (usr != null) { ViewBag.Code = UserManager.GenerateEmailConfirmationToken(usr.Id); ViewBag.UserId = usr.Id; } } return(View()); }
public void CanConfirmEmailAddress() { var user = IdentityUserMother.BasicUser(); UserManager.Create(user); var token = UserManager.GenerateEmailConfirmationToken(user.Id); token.ShouldNotBeEmpty(); var result = UserManager.ConfirmEmail(user.Id, token); result.Succeeded.ShouldBe(true); var newUser = UserManager.FindById(user.Id); newUser.EmailConfirmed.ShouldBe(true); }
/// <summary> /// Systematically confirms the user's email if the url link sent to the user's email /// has been clicked. Only the referred user has access to this email link, which will /// automatically confirm the email upon clicking. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // Obtain code and user Id for email confirmation string code = IdentityHelper.GetCodeFromRequest(Request); string userId = IdentityHelper.GetUserIdFromRequest(Request); ApplicationUser User = new ApplicationUser(); var manager = new UserManager(); User = manager.FindById(userId); var provider = new DpapiDataProtectionProvider("ProjectManagement"); manager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>( provider.Create("EmailConfirmation")); // Confirms email based on received code and user id. IdentityResult validToken = manager.ConfirmEmail(User.Id, code); }
public IHttpActionResult confirmEmailId(int userId, string code) { //throw new HttpResponseException(new HttpResponseMessage(System.Net.HttpStatusCode.BadGateway) { Content = new StringContent("Invalid error"), ReasonPhrase = "ReasonPhrase" }); if (userId == default(int) || code == null) { throw new BusinessException("Some error occured"); //return Request.CreateErrorResponse(HttpStatusCode.NotFound, message); //return View("Error"); } var result = UserManager.ConfirmEmail(Convert.ToString(userId), code); if (result.Succeeded) { return(Ok()); } throw new BusinessException(String.Join(";", result.Errors)); //return View(result.Succeeded ? "ConfirmEmail" : "Error"); }
public ActionResult ConfirmEmail(string userID, string code) { var userStore = new UserStore <IdentityUser>(); UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore); var user = manager.FindById(userID); CreateTokenProvider(manager, EMAIL_CONFIRMATION); try { IdentityResult result = manager.ConfirmEmail(userID, code); if (result.Succeeded) { ViewBag.Message = "You are now registered!"; } } catch { ViewBag.Message = "Validation attempt failed!"; } return(View()); }
public ActionResult ConfirmEmail(string userId, string code) { var userStore = new UserStore <IdentityUser>(); UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore); var user = manager.FindById(userId); CreateTokenProvider(manager, EMAIL_CONFIRMATION); try { IdentityResult result = manager.ConfirmEmail(userId, code); if (result.Succeeded) { IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; authenticationManager .SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, user.UserName), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role); // SignIn() accepts ClaimsIdentity and issues logged in cookie. authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, identity); ViewBag.UserName = user.UserName; ViewBag.Message = "You are now registered!"; } } catch { ViewBag.Message = "Validation attempt failed!"; } return(View()); }
private void CreateRolesandUsers() { ApplicationDbContext context = new ApplicationDbContext(); var provider = new DpapiDataProtectionProvider("ArticleReviewSystem"); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); if (!roleManager.RoleExists("Admin")) { var role = new IdentityRole(); role.Name = "Admin"; roleManager.Create(role); var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", Name = "Super", Surname = "Admin", RegistrationDate = DateTime.Now }; string password = "******"; var superAdminAccount = UserManager.Create(user, password); if (superAdminAccount.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Admin"); UserManager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>( provider.Create("EmailConfirmation")); var token = UserManager.GenerateEmailConfirmationToken(user.Id); var result = UserManager.ConfirmEmail(user.Id, token); } } if (!roleManager.RoleExists("User")) { var role = new IdentityRole(); role.Name = "User"; roleManager.Create(role); } }
public async Task <ActionResult> UserConfirm(UserConfirmModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var user = UserManager.FindById(viewModel.Id); if (user != null) { IdentityResult result = UserManager.ConfirmEmail(viewModel.Id, viewModel.Code); if (result.Succeeded) { //await UserManager.ResetPasswordAsync(user.Id, viewModel.code, viewModel.Password); var resultPW = UserManager.ChangePassword(user.Id, "Pay123456", viewModel.Password); if (resultPW.Succeeded) { Employee e = user.Employee.SingleOrDefault(); e.F124 = 0; db.SaveChanges(); await ApplicationSignInManager.PasswordSignInAsync(user.UserName, viewModel.Password, true, shouldLockout : false); SignCookieAsync(user); return(RedirectToLocal()); } else { AddErrors(resultPW); return(View(viewModel)); }; } else { AddErrors(result); return(View(viewModel)); } } return(View(viewModel)); }
public ActionResult Confirm(string id, string email) { using (IdentityModels entities = new IdentityModels()) { var userStore = new UserStore <User>(entities); var manager = new UserManager <User>(userStore); manager.UserTokenProvider = new EmailTokenProvider <User>(); var user = manager.FindByName(email); if (user != null) { var result = manager.ConfirmEmail(user.Id, id); if (result.Succeeded) { TempData.Add("AccountConfirmed", true); return(RedirectToAction("Login")); } } } return(RedirectToAction("Index", "Home")); }
public IHttpActionResult ConfirmEmail([FromUri] string userId, [FromUri] string code) { try { var token = HttpUtility.UrlDecode(code); IdentityResult result = UserManager.ConfirmEmail(userId, token); bool isEmailConfirmed; if (result.Succeeded) { isEmailConfirmed = true; } else { isEmailConfirmed = false; } return(Ok(isEmailConfirmed)); } catch (Exception) { return(InternalServerError()); } }
public ActionResult ConfirmEmail(string userId, string code) { var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore); var user = manager.FindById(userId); CreateTokenProvider(manager, EMAIL_CONFIRMATION); try { IdentityResult result = manager.ConfirmEmail(userId, code); if (result.Succeeded) { IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; authenticationManager .SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, user.UserName), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role); // SignIn() accepts ClaimsIdentity and issues logged in cookie. authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, identity); ViewBag.UserName = user.UserName; ViewBag.Message = "You are now registered!"; } } catch { ViewBag.Message = "Validation attempt failed!"; } return View(); }
protected override void Seed(ReWork.Model.Context.ReWorkContext context) { base.Seed(context); RoleStore <IdentityRole> roleStore = new RoleStore <IdentityRole>(context); RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(roleStore); if (!roleManager.RoleExists("moderator") && !roleManager.RoleExists("user")) { IdentityRole roleModerator = new IdentityRole() { Name = "moderator" }; IdentityRole roleUser = new IdentityRole() { Name = "user" }; roleManager.Create(roleModerator); roleManager.Create(roleUser); } UserStore <User> userStore = new UserStore <User>(context); UserManager <User> userManager = new UserManager <User>(userStore); var moderator = userManager.FindByName("alex"); if (moderator == null) { moderator = new User() { UserName = "******", Email = "*****@*****.**", FirstName = "Aleksey", LastName = "Programmer", RegistrationdDate = DateTime.UtcNow }; string pathToDefaultImage = HttpContext.Current.Server.MapPath("~/Content/cube-512.png"); byte[] defaultImage = File.ReadAllBytes(pathToDefaultImage); moderator.Image = defaultImage; userManager.Create(moderator, "123456"); userManager.AddToRole(moderator.Id, "user"); userManager.AddToRole(moderator.Id, "moderator"); CustomerProfile customerProfile = new CustomerProfile() { User = moderator }; context.CustomerProfiles.Add(customerProfile); DpapiDataProtectionProvider dataProtectionProvider = new DpapiDataProtectionProvider(); userManager.UserTokenProvider = new DataProtectorTokenProvider <User>(dataProtectionProvider.Create()); string token = userManager.GenerateEmailConfirmationToken(moderator.Id); userManager.ConfirmEmail(moderator.Id, token); } var user = userManager.FindByName("anton"); if (user == null) { user = new User() { UserName = "******", Email = "*****@*****.**", FirstName = "Anton", LastName = "Antonio", RegistrationdDate = DateTime.UtcNow }; string pathToDefaultImage = HttpContext.Current.Server.MapPath("~/Content/cube-512.png"); byte[] defaultImage = File.ReadAllBytes(pathToDefaultImage); user.Image = defaultImage; userManager.Create(user, "123456"); userManager.AddToRole(user.Id, "user"); var customerProfile = new CustomerProfile() { User = user }; context.CustomerProfiles.Add(customerProfile); var dataProtectionProvider = new DpapiDataProtectionProvider(); userManager.UserTokenProvider = new DataProtectorTokenProvider <User>(dataProtectionProvider.Create()); string token = userManager.GenerateEmailConfirmationToken(user.Id); userManager.ConfirmEmail(user.Id, token); } Section programming = context.Sections.SingleOrDefault(p => p.Title.Equals("Programming")); Section design = context.Sections.SingleOrDefault(p => p.Title.Equals("Design sites")); if (programming == null && design == null) { programming = new Section() { Title = "Programming" }; design = new Section() { Title = "Design sites" }; context.Sections.Add(programming); context.Sections.Add(design); } Skill skillCs = context.Skills.FirstOrDefault(p => p.Title.Equals("C#")); Skill skillJa = context.Skills.FirstOrDefault(p => p.Title.Equals("Java")); Skill skillCss = context.Skills.FirstOrDefault(p => p.Title.Equals("Java")); Skill skillScss = context.Skills.FirstOrDefault(p => p.Title.Equals("Java")); if (skillCs == null && skillJa == null && skillCss == null && skillScss == null) { skillCs = new Skill() { Title = "C#", Section = programming }; skillJa = new Skill() { Title = "Java", Section = programming }; skillCss = new Skill() { Title = "CSS", Section = design }; skillScss = new Skill() { Title = "SCSS", Section = design }; context.Skills.Add(skillCs); context.Skills.Add(skillJa); context.Skills.Add(skillCss); context.Skills.Add(skillScss); } var websiteJob = new Job() { Id = 1, CustomerId = moderator.Id, Customer = moderator.CustomerProfile, Title = "create website", Description = "web site must be beautifull, topic this web site its cars", Price = 1000, PriceDiscussed = true, DateAdded = new DateTime(2019, 3, 1) }; var designJob = new Job() { Id = 2, CustomerId = moderator.Id, Customer = moderator.CustomerProfile, Title = "create design for my site", Description = "crate beautifully design, i want see my website in gray colors", Price = 3000, PriceDiscussed = true, DateAdded = new DateTime(2019, 2, 25) }; websiteJob.Skills.Add(skillCs); websiteJob.Skills.Add(skillJa); designJob.Skills.Add(skillCss); designJob.Skills.Add(skillScss); context.Jobs.AddOrUpdate(websiteJob); context.Jobs.AddOrUpdate(designJob); context.SaveChanges(); }
public IdentityResult ConfirmEmail(string userId, string token) { return(_userManager.ConfirmEmail(userId, token)); }
public IActionResult ConfirmEmail(ConfirmEmail model) { return(userManager.ConfirmEmail(model.UserId, model.VerifyCode).Result); }