public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { AdminUser user = (AdminUser)model.GetUser(); var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //var resultRole = userManager.AddToRole(user.Id, "AdminRole"); var resultRole = userManager.AddToRole(user.Id, RoleNames.AdminRole); if (resultRole.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link //string code = await userManager.GenerateEmailConfirmationTokenAsync(user.Id); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await userManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); await workflowMessageService.SendUserRegistrationMessageAsync(userManager, user.Id, Request.Url.Scheme, Url); return(RedirectToAction("Index", "Account")); } else { var errors = string.Join(",", resultRole.Errors); ModelState.AddModelError(string.Empty, errors); } //return RedirectToAction("Index", "Account"); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { // Save file to disk and retreive calculated file name or null if handled exception occure // if user don't provide photo then he don't want photo model.PhotoUrl = Utils.SavePhotoFileToDisk(model.Photo, this, null, model.Photo == null ? true : false); var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var idManager = new IdentityManager(); idManager.AddUserToRole(user.Id, "User"); return(RedirectToAction("Index", "Account")); } else { AddErrors(result); } } // Si nous sommes arrivés là , un échec s’est produit. Réafficher le formulaire return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //Removed because we don't want the user to be signed in until they confirm their e-mail address //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link await SendEmailTokenAsync(user, UserManager.GenerateEmailConfirmationTokenAsync, "Verify", "Confirm your e-mail address", "ConfirmEmail"); ViewBag.Message = "Please check your e-mails. You must confirm your e-mail before you can log on"; return(View("Info")); //return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { //var user = new ApplicationUser() { // UserName = model.UserName, // FirstName = model.FirstName, // LastName = model.LastName, // Email = model.Email //}; var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //await SignInAsync(user, isPersistent: false); return(RedirectToAction("Index", "Account")); } //else //{ // AddErrors(result); //} } initialCategoryCreateAction(); // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Register(RegisterViewModel registerViewModel) { if (!ModelState.IsValid) { return(View(registerViewModel)); } var user = registerViewModel.GetUser(); var salt = RandomString(128); var hash = PasswordHashing.GetPasswordHash(registerViewModel.Password, salt); var userRole = _roleService.GetRoles(r => r.Name == "user").FirstOrDefault(); user.Roles = new List <Role> { userRole }; user.PasswordSalt = salt; user.PasswordHash = hash; try { _userService.AddUser(user); _userService.Save(); return(RedirectToAction("Login")); } catch { ModelState.AddModelError("", $"User with login {user.Login} already exists!"); return(View(registerViewModel)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(RedirectToAction("Index", "Account", new { errorCode = 1, })); } else { return(RedirectToAction("Index", "Account", new { errorCode = 2, })); } } else { return(RedirectToAction("Index", "Account", new { errorCode = 3, })); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); //var user = new ApplicationUser() { UserName = model.UserName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { snedmail.NewAccount(model.Name, model.Email, model.PhoneNumber.ToString(), model.UserName, model.Password); propic thiuser = new propic(); thiuser.username = model.UserName; thiuser.proimg = "whopci.png"; xdb.ProPics.Add(thiuser); point zpoint = new point(); zpoint.username = model.UserName; zpoint.points = 0; zpoint.UpdatedDate = DateTime.Now; xdb.Points.Add(zpoint); xdb.SaveChanges(); //await SignInAsync(user, isPersistent: false); return(RedirectToAction("Index", "Home")); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.password); if (result.Succeeded) { return(RedirectToAction("Index", "Account")); } } return(View(model)); }
public async Task <IHttpActionResult> Register(RegisterViewModel model) { var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(Ok("success")); } else { return(Ok(result)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(RedirectToAction(actionName: "Index", controllerName: "Account")); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); var result = await _userManager.CreateAsync(user, model.Password); _employeeService.AddVacation(_userManager.Users.Last().UserId); if (result.Succeeded) { return(RedirectToAction("Index", "Account")); } } ViewBag.Positions = new SelectList(_positionService.GetAllPositions(), "Id", "Name"); return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { ApplicationUser applicationUser = model.GetUser(); // Gets user object created from submitted form data held in 'model' IdentityResult result = await UserManager.CreateAsync(applicationUser, model.Password); if (result.Succeeded) { AspNetUser user = db.AspNetUsers.FirstOrDefault(u => u.Id == applicationUser.Id); user.FirstName = model.FirstName; user.LastName = model.LastName; user.AvatarFilePath = Server.MapPath("~\\img\\avatars\\default-avatar.png"); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); // Automatically signin newly registered user await SignInAsync(applicationUser, isPersistent : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(applicationUser.Id); var callbackUrl = Url.Action( "ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(applicationUser.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); TempData["message"] = "Thank you for registratering!. Please confirm your account before signing in."; return(RedirectToAction("Index", "Home")); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase upload) { if (ModelState.IsValid) { //var user = new ApplicationUser { UserName = model.UserName,LastName = model.LastName,FirstName = model.FirstName,UserImage = model.UserImage, Email = model.Email }; var user = model.GetUser(); if (upload != null && upload.ContentLength > 0) { var avatar = new File { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Avatar, ContentType = upload.ContentType }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { avatar.Content = reader.ReadBytes(upload.ContentLength); reader.Close(); } user.Files = new List <File> { avatar }; } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Account")); } //AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { /*var user = new SYSTEM_USER() { UserName = model.UserName, * Email = model.Email }; */ var user = model.GetUser(); try { var result = UserManager.Create(user, model.Password); if (result.Succeeded) { //await SignInAsync(user, isPersistent: false); return(RedirectToAction("Index", "Account")); } else { AddErrors(result); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Register( [FromBody] RegisterViewModel model) { var user = model.GetUser(); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddClaimsAsync(user, model.GetClaims()); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("confirmEmail", "Account", new { userId = user.Id, code }, protocol: HttpContext.Request.Scheme); await _emailService.ConfirmAccount(model.Email, callbackUrl); return(Ok()); } return(BadRequest("User creation failed.")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //await SignInAsync(user, isPersistent: false); return(RedirectToAction("Index", "Account")); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = model.GetUser(); user.User_Active = true; //get organization level details var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // SendEmail(user, model); //return RedirectToAction("Index", "Account"); return(RedirectToAction("Index", "AdminLte")); } } //get orgn and org levels var organization = from b in _db.Organizations select new SelectListItem() { Text = b.Name, Value = b.OrgId.ToString() }; var orgLevelTypes = from b in _db.OrgLevelTypes select new SelectListItem() { Text = b.Name, Value = b.typeId.ToString() }; model.Organizations = organization.ToList(); model.orgLevelTypes = orgLevelTypes.ToList(); // If we got this far, something failed, redisplay form return(View(model)); }