public ActionResult Register() { AccountEditVM model = new AccountEditVM(); TryUpdateModel(model); User user = new User(); UsersService userService = new UsersService(); if (userService.CheckUsernameOrMail(model) != null) { ModelState.AddModelError("", "Username or email already exists!"); } if (!ModelState.IsValid) { return(View(model)); } user.FirstName = model.FirstName; user.LastName = model.LastName; user.Username = model.Username; user.Email = model.Email; user.Password = Guid.NewGuid().ToString(); userService.Save(user); EmailService.SendEmail(user, ControllerContext); return(this.RedirectToAction("Login")); }
public ActionResult Register() { AccountEditVM model = new AccountEditVM(); TryUpdateModel(model); PhoneBook.Models.User user = new Models.User(); UsersService userService = new UsersService(); if (userService.CheckUsernameOrMail(model) != null) { ModelState.AddModelError("", "Username or email already exists!"); } if (!ModelState.IsValid) { return(View(model)); } Mapper.Map(model, user); user.Password = Guid.NewGuid().ToString(); userService.Save(user); Task.Run(() => EmailService.SendEmail(user, ControllerContext)); return(this.RedirectToAction(c => c.Login())); }
public async Task <IActionResult> Edit(AccountEditVM model) { var user = await _userManager.GetUserAsync(HttpContext.User); string uniqueFileName = UploadedFile(model); if (user == null) { return(View("EditFailure")); } else { user.FirstName = model.FirstName; user.LastName = model.LastName; user.DisplayName = model.DisplayName; user.PhoneNumber = model.PhoneNumber; user.ProfileImage = uniqueFileName; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(View("EditConfirmation")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); } }
public User CheckUsernameOrMail(AccountEditVM user) { UsersService userService = new UsersService(); User userMail = userService.GetAll().FirstOrDefault((u => u.Email == user.Email || u.Username == user.Username.ToLower())); if (userMail != null) { return(userMail); } else { return(null); } }
private string UploadedFile(AccountEditVM model) { string uniqueFileName = null; if (model.ProfileImage != null) { string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfileImage.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.ProfileImage.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> Edit() { // Fetch the userprofile var user = await _userManager.GetUserAsync(HttpContext.User); if (user == null) { return(View("EditFailure")); } // Construct the viewmodel AccountEditVM model = new AccountEditVM(); model.FirstName = user.FirstName; model.LastName = user.LastName; model.DisplayName = user.DisplayName; model.PhoneNumber = user.PhoneNumber; return(View(model)); }
public ActionResult Register(string str) { AccountEditVM model = new AccountEditVM(); return(View(model)); }