public IActionResult Register() { RegisterNewUserViewModel model = new RegisterNewUserViewModel(); GetCombos(model); return(View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (this.ModelState.IsValid) { var user = await this.userHelper.GetUserByEmailAsync(model.Username); if (user == null) { user = new User { FirstName = model.FirtsName, lastName = model.LastName, Email = model.Username, UserName = model.Username }; var result = await this.userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "El usuario no fue creado"); return(this.View(model)); } } } return(this.View(model)); }
public async Task <IActionResult> Edit(RegisterNewUserViewModel vm) { if (!ModelState.IsValid) { var user = await userManager.FindByIdAsync(vm.Id); if (user != null) { user.FirstName = vm.FirstName; user.LastName = vm.LastName; var result = await userManager.UpdateAsync(user); if (!result.Succeeded) { ModelState.AddModelError(string.Empty, "La información de la cuenta no pudo modificarse correctamente"); return(View(vm)); } ViewBag.Message = "La información de la cuenta ha sido actualizada"; return(View(vm)); } } return(View(vm)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (ModelState.IsValid) { ApplicationUser user; if (!_context.ApplicationUserGroups.Where(u => u.School.Id == Guid.Parse(HttpContext.Session.GetString("School"))).Any(g => g.GroupName == model.Group)) { _context.ApplicationUserGroups.Add(new ApplicationUserGroup { GroupName = model.Group }); await _context.SaveChangesAsync(); } user = new ApplicationUser { UserName = model.Username, Email = model.Email, Group = _context.ApplicationUserGroups.First(g => g.GroupName == model.Group), School = _context.Schools.First(s => s.Id == Guid.Parse(HttpContext.Session.GetString("School"))) }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _userManager.AddToRoleAsync(user, model.RoleName).GetAwaiter().GetResult(); } return(RedirectToAction("Index")); } List <ApplicationUserGroup> groups = _context.ApplicationUserGroups.Where( u => u.School.Id == Guid.Parse(HttpContext.Session.GetString("School"))).ToList(); model.Groups = JsonConvert.SerializeObject(groups.Select(g => g.GroupName).ToList()); return(View(model)); }
public ActionResult RegisterNewUser(string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; RegisterNewUserViewModel model = new RegisterNewUserViewModel(); return(View(model)); }
public async Task <IActionResult> RegisterNewUser(RegisterNewUserViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, IsActive = true }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { TempData["success"] = String.Format("Bruker ble opprettet for {0} {1} og e-post med instrukser for fullføring av registreringen er sendt til {2}.", model.FirstName, model.LastName, model.Email); // Email example from AccountController: var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); return(RedirectToAction("RegisterNewUser")); } } // Something went wrong, show form again TempData["error"] = "Feil under oppretting av bruker."; return(View(model)); }
public async Task <IActionResult> NewUser(RegisterNewUserViewModel vm) { if (ModelState.IsValid) { var newUser = new ApplicationUser { UserName = vm.Email, Email = vm.Email, Name = vm.Name, Surname = vm.Surname }; var result = await _userManager.CreateAsync(newUser, vm.Password); await _userManager.AddToRoleAsync(newUser, "Member"); if (result.Succeeded) { await _signInManager.SignInAsync(newUser, false); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(Content("task completed")); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (this.ModelState.IsValid) { var user = await this.userHelper.GetUserByEmailAsync(model.Username); if (user == null) { // var city = await this.countryRepository.GetCityAsync(model.CityId); var owner = new Owner { Name = model.FirstName, Lastname = model.LastName }; await this.context.Owners.AddAsync(owner); await this.context.SaveChangesAsync(); user = new ApplicationUser { Name = model.FirstName, Lastname = model.LastName, Email = model.Username, UserName = model.Username, Owner = owner, // Address = model.Address, PhoneNumber = model.PhoneNumber, //CityId = model.CityId, //City = city }; var result = await this.userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "Usuario no pudo ser creado"); return(this.View(model)); } var myToken = await this.userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = this.Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken }, protocol: HttpContext.Request.Scheme); this.mailHelper.SendMail(model.Username, "911 Reactions Email confirmation", $"<h1>911 Reactions Email confirmation</h1>" + $"Para permitir el acceso a tu usuario, " + $"porfavor, has click en este link:</br></br><a href = \"{tokenLink}\">Confirmar Correo</a>"); this.ViewBag.Message = "Las instrucciones para permitir el acceso a tu usuario, han sido enviadas a tu correo."; return(this.View(model)); } this.ModelState.AddModelError(string.Empty, "El usuario ya esta registrado."); } return(this.View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { var user = await _userHelper.GetUserByEmailAsync(model.Username); if (user == null) { City city = await _countryRepository.GetCityAsync(model.CityId); user = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Username, PhoneNumber = model.PhoneNumber, UserName = model.Username, SocialSecurityNumber = model.SocialSecurityNumber, TaxNumber = model.TaxNumber, Address = model.Address, City = city, isActive = true, }; var result = await _userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created. Please, contact support!"); return(this.View(model)); } var result2 = await _userHelper.AddUserToRoleAsync(user, "Customer"); var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); // Criar um link que vai levar lá dentro uma acção. Quando o utilizador carregar neste link, // vai no controlador Account executar a action "ConfirmEmail"(Ainda será feita) // Este ConfirmEmail vai receber um objecto novo que terá um userid e um token. var tokenLink = this.Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken, }, protocol: HttpContext.Request.Scheme); _mailHelper.SendMail(model.Username, "Email confirmation", $"<h1>Email Confirmation</h1>" + $"To allow the user, " + $"plase click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>"); this.ViewBag.Message = "Go to your email to activate your account"; return(this.View(model)); } this.ModelState.AddModelError(string.Empty, "The user already exists"); return(View(model)); }
public IActionResult Register() { var model = new RegisterNewUserViewModel { Roles = this.userHelper.GetComboRoles(), }; return(this.View(model)); }
public IActionResult Register() { var model = new RegisterNewUserViewModel { Genders = this.combosHelper.GetComboGenders() }; return(View(model)); }
public async Task <IActionResult> Register() { RegisterNewUserViewModel model = new RegisterNewUserViewModel(); var roles = await _userHelper.GetAllListRoles(); model.Roles = roles.ToList(); return(this.View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (ModelState.IsValid) { var user = await _userHelper.GetUserByEmailAsync(model.Username); if (user == null) { user = new User { FirstNames = model.FirstNames, LastNames = model.LastNames, Email = model.Username, UserName = model.Username, Address = model.Address, PhoneNumber = model.PhoneNumber, DocumentId = model.DocumentId, DocumentNumber = model.DocumentNumber, TIN = model.TIN, BirthDate = model.BirthDate }; var result = await _userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { ModelState.AddModelError(string.Empty, "An error occurred creating the user"); return(View(model)); } await _userHelper.AddUserToRoleAsync(user, "Client"); var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken }, protocol: HttpContext.Request.Scheme); _mailHelper.SendMail(model.Username, "Email confirmation", $"<h1>Email Confirmation</h1>" + $"To allow the user, " + $"plase click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>"); ViewBag.Message = "User created successfully, please check your e-mail to enable your account"; return(View(model)); } ModelState.AddModelError(string.Empty, "The username already exists"); } model.Documents = _documentRepository.GetComboDocuments(); return(View(model)); }
public IActionResult Register() { var model = new RegisterNewUserViewModel { Countries = _countryRepository.GetComboCountries(), RoleChoices = _userHelper.GetComboRoles() }; return(this.View(model)); }
public IActionResult RegisterClient() { var model = new RegisterNewUserViewModel { Countries = _countryRepository.GetComboCountries(), Genders = _clientRepository.GetComboGenders() }; return(View(model)); }
public IActionResult Register() { var model = new RegisterNewUserViewModel { Countries = this.repository.GetComboCountries(), Cities = this.repository.GetComboCities(0) }; return(this.View(model)); }
public ActionResult Register() { var model = new RegisterNewUserViewModel() { Countries = this.countryRepository.GetComboCountries(), Cities = this.countryRepository.GetComboCities(0), }; return(View(model)); }
public IActionResult Register() { //TODO: ver el rol con un combo dara de alta los roles en el seeder var model = new RegisterNewUserViewModel { Roles = userHelper.GetComboRoles() }; return(View(model)); }
public IActionResult Register(int stateId)//this register is associated with the Register that is at login and RegisterNewUserViewModel { var model = new RegisterNewUserViewModel { States = _stateRepository.GetComboStates(), Cities = _stateRepository.GetComboCities(0) }; return(this.View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (this.ModelState.IsValid) { var user = await this.userHelper.GetUserByEmailAsync(model.Username); if (user == null) { user = new User { Address = model.Address, FirstName = model.FirstName, LastName = model.LastName, Email = model.Username, UserName = model.Username, IsEnabled = true, }; var result = await this.userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created."); return(this.View(model)); } var roleName = await this.userHelper.GetRoleAsync(model.RoleId.ToString()); var role = roleName.Name; var result2 = this.userHelper.AddUserToRoleAsync(user, role); var loginViewModel = new LoginViewModel { Password = model.Password, RememberMe = false, Username = model.Username }; var result3 = await this.userHelper.LoginAsync(loginViewModel); if (result3.Succeeded) { return(this.RedirectToAction("Index", "Home")); } this.ModelState.AddModelError(string.Empty, "The user couldn't be login."); return(this.View(model)); } this.ModelState.AddModelError(string.Empty, "The username is already registered."); } return(this.View(model)); }
public IActionResult Register() { var model = new RegisterNewUserViewModel(); var groups = _context.ApplicationUserGroups.Where( u => u.School.Id == Guid.Parse(HttpContext.Session.GetString("School"))).Select(g => g.GroupName).ToList(); var roles = _context.Roles.Where(r => r.Name == "Schooladmin" || r.Name == "Leraar"); model.Roles = new SelectList(roles, "Name"); model.Groups = JsonConvert.SerializeObject(groups); return(View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (this.ModelState.IsValid) { var user = await this.userHelper.GetUserByEmailAsync(model.Username); if (user == null) { var city = await this.countryRepository.GetCityAsync(model.CityId); user = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Username, UserName = model.Username, Address = model.Address, PhoneNumber = model.PhoneNumber, CityId = model.CityId, City = city }; var result = await this.userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created."); return(this.View(model)); } var loginViewModel = new LoginViewModel { Password = model.Password, RememberMe = false, Username = model.Username }; var result2 = await this.userHelper.LoginAsync(loginViewModel); if (result2.Succeeded) { return(this.RedirectToAction("Index", "Home")); } this.ModelState.AddModelError(string.Empty, "The user couldn't be login."); return(this.View(model)); } this.ModelState.AddModelError(string.Empty, "The username is already registered."); } return(this.View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (ModelState.IsValid) { var user = await _userHelper.GetUserByEmailAsync(model.Username); if (user == null) { var city = await _countryRepository.GetCityAsync(model.CityId); user = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Username, UserName = model.Username, Address = model.Address, PhoneNumber = model.PhoneNumber, CityId = model.CityId, City = city }; var result = await _userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created."); return(this.View(model)); } var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = this.Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken, }, protocol: HttpContext.Request.Scheme); _mailHelper.SendMail(model.Username, "Email confirmation", $"<h1>Email Confirmation</h1>" + $"To allow the user, " + $"plase click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>"); this.ViewBag.Message = "The instructions to allow your user has been sent to email."; return(this.View(model)); } this.ModelState.AddModelError(string.Empty, "The user already exists."); } return(View(model)); }
public IActionResult Register() { var model = new RegisterNewUserViewModel { //recupera las ciudades y piases Countries = this.countryRepository.GetComboCountries(), Cities = this.countryRepository.GetComboCities(0) }; return(this.View(model)); }
/// <summary> /// Register page get /// </summary> /// <returns></returns> public IActionResult Register() { var model = new RegisterNewUserViewModel { Documents = _documentRepository.GetComboDocuments() }; View(model); return(View()); }
public IActionResult Register() { //delete country //return this.View(); var model = new RegisterNewUserViewModel { Countries = this.countryRepository.GetComboCountries(), Cities = this.countryRepository.GetComboCities(0) }; return(this.View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (this.ModelState.IsValid) { // Método para validar si existe y traer el usuario ingresado var user = await this.userHelper.GetUserByEmailAsync(model.Username); if (user == null) { // Llenamos la entidad User user = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Username, UserName = model.Username }; // Método para crear usuario var result = await this.userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created."); return(this.View(model)); } var loginViewModel = new LoginViewModel { Username = model.Username, Password = model.Password, RememberMe = false }; // Método para iniciar sesión var result2 = await this.userHelper.LoginAsync(loginViewModel); if (result2.Succeeded) { return(this.RedirectToAction("Index", "Home")); } this.ModelState.AddModelError(string.Empty, "The user couldn't be login."); return(this.View(model)); } this.ModelState.AddModelError(string.Empty, "The username is already registered."); } return(this.View(model)); }
public void saveNewRegisterationData(RegisterNewUserViewModel registerNewUserViewModel) { tbl_Login saveNewRegistrationDataToDB = new tbl_Login(); saveNewRegistrationDataToDB.UserID = registerNewUserViewModel.UserEmail; saveNewRegistrationDataToDB.UserEmail = registerNewUserViewModel.UserEmail; saveNewRegistrationDataToDB.UserPassword = registerNewUserViewModel.UserPassword; saveNewRegistrationDataToDB.IsActive = false; saveNewRegistrationDataToDB.LoginAttempts = 0; saveNewRegistrationDataToDB.IsLocked = false; context.tbl_Login.Add(saveNewRegistrationDataToDB); context.SaveChanges(); }
public async Task <IActionResult> RegisterClient(RegisterNewUserViewModel model) { if (ModelState.IsValid) { var user = await _userHelper.GetUserByEmailAsync(model.EmailAddress); if (user == null) { try { var country = await _countryRepository.GetByIdAsync(model.CountryId); user = _converterHelper.ToUser(model, country); var result = await _userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created."); return(this.View(model)); } await _userHelper.AddUSerToRoleAsync(user, user.SelectedRole); var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = this.Url.Action("ConfirmEmailClient", "Account", new { userid = user.Id, token = myToken }, protocol: HttpContext.Request.Scheme); _mailHelper.SendToNewClient(user.Email, tokenLink, user.Name); await _notificationHelper.CreateNotificationAsync(user.GuidId, UserType.Admin, "New Client Registration", NotificationType.NewClient); return(RedirectToAction(nameof(ConfirmRegistration))); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } } this.ModelState.AddModelError(string.Empty, "There's already an account with this email address."); } model.Countries = _countryRepository.GetComboCountries(); model.Genders = _clientRepository.GetComboGenders(); return(View(model)); }
public async Task <IActionResult> Register(RegisterNewUserViewModel model) { if (this.ModelState.IsValid) { var user = await this.userHelper.GetUserByEmailAsync(model.UserName); if (user == null) { user = new User { FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, UserName = model.UserName, Email = model.UserName, }; var result = await this.userHelper.AddUserAsync(user, model.Password); if (result != IdentityResult.Success) { this.ModelState.AddModelError(string.Empty, "The user couldn't be created"); return(View(model)); } //TODO:Crear método para mostrar combo de roles //TODO: cambiar viewmodel que maneje combo de roles //TODO: cambiar vista para manejar combo de roles //TODO: seleccion y asignacion del rol //await this.userHelper.AddUserToRoleAsync(user, "Admin"); //await this.userHelper.AddUserToRoleAsync(user, "User"); await this.userHelper.AddUserToRoleAsync(user, "Lender"); var result2 = await this.userHelper.LoginAsync( model.UserName, model.Password, true); if (result2.Succeeded) { return(this.RedirectToAction("Index", "Home")); } this.ModelState.AddModelError(string.Empty, "The user couldn't be login"); return(View(model)); } this.ModelState.AddModelError(string.Empty, "The user is already registered"); return(View(model)); } //TODO: checar combo de roles return(View(model)); }
public ActionResult Index(FormCollection formCollection, RegisterNewUserViewModel registration_view_model_data) { //if the form is valid if (ModelState.IsValid) { string temp_email = SecurityHelper.StripHTML(registration_view_model_data.Email); string temp_user_name = SecurityHelper.StripHTML(registration_view_model_data.Username); //check to see if the user is already in the database var user_in_question = (from usr in db.Users where usr.email.Equals(temp_email) select usr); //if this is more than zero, it means the user is already in the database if (user_in_question.FirstOrDefault() != null) { ViewBag.Message = "You are already in the database! Please just login."; return View("NewUserRegistrationView"); } //check to see if the username is unique var username_in_question = (from usr in db.Users where usr.username.Equals(temp_user_name) select usr); //if this is more than zero, it means the user is already in the database if (username_in_question.FirstOrDefault() != null) { ViewBag.Message = "User name must be unique. This one is already in the database."; return View("NewUserRegistrationView"); } //check if the password matches if (!SecurityHelper.StripHTML(registration_view_model_data.ConfirmationPassword).Equals(SecurityHelper.StripHTML(registration_view_model_data.Password))) { ViewBag.Message = "The two passwords have to match."; return View("NewUserRegistrationView"); } //create a new user User user = new User(); user.firstname = SecurityHelper.StripHTML(registration_view_model_data.FirstName); user.lastname = SecurityHelper.StripHTML(registration_view_model_data.LastName); user.datetime_registered = DateTime.Now; user.role = "user"; user.username = temp_user_name; user.sex = formCollection["sex"]; user.location = formCollection["location"]; user.age = Convert.ToInt32(SecurityHelper.StripHTML(registration_view_model_data.Age.ToString())); //encrypt the password user.password = AuthenticationHelper.ENCRYPT_ME(SecurityHelper.StripHTML(registration_view_model_data.Password)); user.email = temp_email; user.image_url = formCollection["sex"].Equals("m") ? "~/Content/Images/male_default.jpg" : "~/Content/Images/female_default.jpg"; try { //submit into the database db.Users.Add(user); db.SaveChanges(); return RedirectToAction("Index", "Login"); } catch (InvalidOperationException ex) { ViewBag.Message = "Email is already in the database."; return View("NewUserRegistrationView"); } catch (FormatException ex) { ViewBag.Message = "You need to enter a numberical value for your age."; return View("NewUserRegistrationView"); } catch (InvalidCastException ex) { ViewBag.Message = "The age conversion totally failed."; return View("NewUserRegistrationView"); } catch (OverflowException) { ViewBag.Message = "Your age is way to big. Enter a value between 0 and 120"; return View("NewUserRegistrationView"); } catch (Exception ex) { ViewBag.Message = "Something weird happend. Please try again."; //redirect to the registration page again return View("NewUserRegistrationView"); } } else { ViewBag.Message = "Too many errors. Please fill out the form again."; return View("NewUserRegistrationView"); } }