public ActionResult SignUp(SignUpModel model) { if (ModelState.IsValid) { var siag = db.USERs.FirstOrDefault(x => x.Email == model.Email); if (siag == null) { var sig = new USER(); sig.Address = model.Address; sig.Email = model.Email; sig.FullName = model.FullName; sig.Password = model.Password; sig.Phone = model.Phone; sig.Role = "0"; sig.Status = true; db.USERs.Add(sig); db.SaveChanges(); ViewBag.Success = "Đăng ký thành công"; model = new SignUpModel(); return(RedirectToAction("Login", "Agency")); } else { ModelState.AddModelError("", "Email đã tồn tại"); } return(View()); } else { ModelState.AddModelError("", "Đăng ký không thành công"); } return(View()); }
public async Task <IActionResult> SignUp(SignUpModel model) { AccountStatusPair asp = await repository.GetAccountStatus(Request, Response); if (asp.status != AccountStatus.Invalid) { return(RedirectToAction("Index")); } if ((ModelState.IsValid) && (model.IsModelValid())) { Account account = new Account(model.Username, model.Email, model.Password, model.FirstName, model.LastName, model.GetGender()); account.Verified = true; // SINCE THERE IS NO WAY OF CONFIRMING THE EMAIL ADDRESS if (await repository.AddAccount(account)) { logger.LogInformation($"User @{account.Username} (ID: {account.Id}) registered with email {account.Email} (Verification code: {account.VerificationCode})"); try { // Services.Email.SendVerification(account.Email, account.VerificationCode.ToString()); } catch (Exception ex) { logger.LogError($"AUTO-MAIL FAILED: {ex.Message}"); return(RedirectToAction("Error")); } return(View("Registered", new RegisteredModel() { FirstName = account.FirstName, Email = account.Email })); } } return(RedirectToAction("Error")); }
public IActionResult SignUp(SignUpModel model) { if (ModelState.IsValid) { if (_registrationService.UserExists(model.FirstName, model.LastName, DateTime.Parse(model.Day + model.Month + model.Year), model.Gender)) { model.Existed = true; return(View("SignUpAlreadyExists", model)); } else { model.Existed = false; return(View("SignUpCredentials", new SignUpCredentialsModel { FirstName = model.FirstName, LastName = model.LastName, Day = model.Day, Month = model.Month, Year = model.Year, Gender = model.Gender, Existed = model.Existed })); } } return(View(model)); }
public async Task LoginController_SignUp_ThrowsUnknownErrorOnUnhandledException(bool useCustomException) { // Arrange var requestData = new SignUpModel { Email = email, Password = password, UserName = name }; if (useCustomException) { mockAuthService.Setup(uD => uD.SignUp(It.IsAny <SignUpModel>())).ThrowsAsync(ErrorStatusCode.UnknownError); } else { mockAuthService.Setup(uD => uD.SignUp(It.IsAny <SignUpModel>())).ThrowsAsync(new Exception("Any exception message")); } // Act var result = await loginController.SignUp(requestData, false) as ObjectResult; // Assert mockAuthService.Verify(uD => uD.SignUp(It.IsAny <SignUpModel>()), Times.Once()); Assert.NotNull(result); Assert.IsType <ErrorDetail>(result.Value); Assert.Equal(ErrorMessages.UnknownError, (result.Value as ErrorDetail).Message); Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode); }
public void GetUserWithCorrectData() { var name = "Maurício Luís dos Santos"; var email = "*****@*****.**"; var password = "******"; var prefix = "21"; var number = "31785826"; var model = new SignUpModel() { nome = name, email = email, senha = password, telefones = new List <TelphoneModel>() { new TelphoneModel() { ddd = prefix, numero = number } } }; var factory = new UsersFactory(model); factory.Create(); var user = factory.GetUser(); Assert.Equal(email, user.Email); }
public async Task <IActionResult> SignUp(SignUpModel model) { if (ModelState.IsValid) { var user = _cognitoUserPool.GetUser(model.Email); if (user.Status != null) { ModelState.AddModelError("UserExists", "User with this email already exists."); return(View(model)); } user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(RedirectToAction("Confirm")); } else { foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(View(model)); } } return(View(model)); }
public async Task <(UserModel user, string message)> RegisterUser(SignUpModel model) { var userExists = await repository.FirstOrDefault(r => r.Username == model.Username); if (userExists == null) { AuthUtil.CreatePasswordHash(model.Password, out byte[] passwordHash, out byte[] passwordSalt); var userDetails = new User { CreatedAt = DateTime.Now, PasswordHash = passwordHash, PasswordSalt = passwordSalt, Username = model.Username, Email = model.Email, Role = UserRoles.AppUser }; var newuser = await repository.Insert(userDetails); var returnView = new UserModel { Username = newuser.Username, Email = newuser.Email, Id = newuser.ID }; return(user : returnView, message : "User created successfully."); } return(user : null, message : $"User {model.Username} exists already!"); }
public void GetTelphoneWithCorrectData() { var name = "Maurício Luís dos Santos"; var email = "*****@*****.**"; var password = "******"; var prefix = "21"; var number = "31785826"; var model = new SignUpModel() { nome = name, email = email, senha = password, telefones = new List <TelphoneModel>() { new TelphoneModel() { ddd = prefix, numero = number } } }; var factory = new UsersFactory(model); factory.Create(); var profile = factory.GetProfile(); Assert.Equal(prefix, profile.Telphones.First().Prefix.ToString()); Assert.Equal(number, profile.Telphones.First().Number); }
public ActionResult SignUp() { var model = new SignUpModel(); LoadLabelSignUpModel(model); return(View(model)); }
public void GetUserWhenTokeExists() { var name = "Maurício Luís dos Santos"; var email = "*****@*****.**"; var password = "******"; var prefix = "21"; var number = "31785826"; var model = new SignUpModel() { nome = name, email = email, senha = password, telefones = new List <TelphoneModel>() { new TelphoneModel() { ddd = prefix, numero = number } } }; var response = GetRegisterUserService().Register(model); var registeredUserModel = GetGetUserService().Get(response.token); /* * Assert.Equal(registeredUserModel.nome, name); * Assert.Equal(registeredUserModel.email, email);*/ }
public async Task <IActionResult> SignUp(SignUpModel model) { BuilderDTO builder = _mapper.Map <BuilderDTO>(model); await _signUpService.SingUp(builder); return(Ok()); }
public async Task SignUpAsync(SignUpModel model, CancellationToken cancellationToken = default) { var emailExists = await _userVerificationManager.EmailExistsAsync(model.Email, cancellationToken); if (emailExists) { throw new BadRequestException( new ErrorModel(nameof(model.Email), "Email already exists")); } var usernameExists = await _userVerificationManager.UserNameExistsAsync(model.UserName, cancellationToken); if (usernameExists) { throw new BadRequestException( new ErrorModel(nameof(model.UserName), "Username already exists")); } var result = await _userManager.CreateAsync(new User { Email = model.Email, UserName = model.UserName }, model.Password); if (!result.Succeeded) { throw new BadRequestException(GetErrorModel(result.Errors)); } }
public ActionResult AfterRegister() { SignUpModel newSignUp = new SignUpModel(); newSignUp.Username = Request["Username"]; newSignUp.Password = Request["Password"]; newSignUp.ConfirmPassword = Request["ConfirmPassword"]; if (Request["Gender"] == "M") { newSignUp.Gender = 'M'; } else { newSignUp.Gender = 'F'; } if (Request["AcTerms"] == "false") { newSignUp.AcTerms = false; } else { newSignUp.AcTerms = true; } TempData["ssu"] = newSignUp; if (newSignUp.Password != newSignUp.ConfirmPassword) { return(RedirectToAction("WrongPassword")); } if (newSignUp.AcTerms == false) { return(RedirectToAction("NotAC")); } return(RedirectToAction("Success")); }
private async Task <HttpResponseMessage> SignUp(SignUpModel signUpModel) { var response = await _client.PostAsync(@"auth/signup", signUpModel.ToJsonContent()); response.EnsureSuccessStatusCode(); return(response); }
public async Task <User> CreateUserAccountAsync(SignUpModel model) { var signUpToken = SecurityUtils.GenerateSecureToken(); var user = new User { Role = UserRole.User, FirstName = model.FirstName, LastName = model.LastName, PasswordHash = model.Password.GetHash(), Email = model.Email, IsEmailVerified = false, SignupToken = signUpToken }; await _userRepository.InsertAsync(user); await _emailService.SendSignUpAsync(new SignUpEmailModel { Email = model.Email, FirstName = model.FirstName, SignUpToken = signUpToken }); return(user); }
public SignUpViewModel(Action <object> navigate, StaticCodeAnalysisServiceClient codeAnalysisServiceClient) { SignUpModel = new SignUpModel(); Navigate = navigate; CodeAnalysisServiceClient = codeAnalysisServiceClient; SignUp = new RelayCommand(OnSignUp, o => true); }
public async Task <IActionResult> SignUp(SignUpModel model) { // if there are no errors in the model from the view, then the user is created if (ModelState.IsValid) { //if there is no user with that username then the same one is created if ((await _cineUserManager.FindUserByUserName(model.Username)) == null) { // verify that the passwords match, if they don't match then the error is reported if (!model.MatchPasswords()) { ModelState.AddModelError("SignUp", "Las contraseñas no coinciden"); return(View(model)); } // create user IdentityResult result = await _cineUserManager.SignUpUser(model, "Member"); if (result.Succeeded) { return(RedirectToAction("Index", "Home", null)); } ModelState.AddModelError("SignUp", string.Join(string.Empty, result.Errors.Select(error => error.Description))); return(View(model)); } else { ModelState.AddModelError("SignUp", "El nombre de usuario ya está en uso."); } } return(View(model)); }
public void CreateObjects() { var name = "Maurício Luís dos Santos"; var email = "*****@*****.**"; var password = "******"; var prefix = "21"; var number = "31785826"; var model = new SignUpModel() { nome = name, email = email, senha = password, telefones = new List <TelphoneModel>() { new TelphoneModel() { ddd = prefix, numero = number } } }; var factory = new UsersFactory(model); factory.Create(); Assert.NotNull(factory.GetUser()); Assert.NotNull(factory.GetProfile()); }
public async Task <IActionResult> Signup() { var model = new SignUpModel(); model.ExternalLogins.AddRange(await _signInService.GetExternalAuthenticationSchemesAsync()); return(View(model)); }
public async Task <ActionResult <string> > SignUp(SignUpModel newuser) { var signup = mapper.Map <SignUp>(newuser); var EmailisValid = await user.FindByEmailAsync(signup.Email); if (EmailisValid == null) { IdentityResult identity = await user.CreateAsync(signup, signup.Password); if (identity.Succeeded) { await user.AddClaimAsync(signup, new Claim(ClaimTypes.Role, "User")); await user.AddToRoleAsync(signup, "User"); var result = await sign.PasswordSignInAsync(signup.UserName, signup.Password, false, true); if (result.Succeeded) { return(this.StatusCode(StatusCodes.Status201Created, $"Welcome,{signup.UserName} Your account has been created")); } } else { return(this.StatusCode(StatusCodes.Status400BadRequest, $"Invalid password, follow the password requirements {identity.Errors} ")); } } return(BadRequest("This email is currently used by another user")); }
public async Task <IActionResult> SignUp(SignUpModel model) { ViewBag.Title = "ДУБ - Регистрация"; if (!ModelState.IsValid) { return(View()); } if (await CheckEmail(model.Email)) { ModelState.AddModelError("Email", "Пользователь с данной электронной почтой уже зарегистрирован!"); return(View()); } Autor autor = new Autor(); model.ToAutor(ref autor); await _oak.Autors.AddAsync(autor); _oak.SaveChanges(); await Authenticate(model.Email); return(RedirectToAction("All", "Articles")); }
public ActionResult SignUp(SignUpModel GetData) { WebAppDBEntities db = new WebAppDBEntities(); var userDatails = db.Accesses.Where(x => x.Username == GetData.UserName).FirstOrDefault(); if (userDatails == null) { Access GetAccess = new Access { Username = GetData.UserName, Password = GetData.Password }; Person GetPerson = new Person { FirstName = GetData.FirstName, LastName = GetData.LastName, EmailAddress = GetData.EmailAddress, Phone = GetData.Phone, Username = GetData.UserName }; db.Accesses.Add(GetAccess); db.People.Add(GetPerson); db.SaveChanges(); return(RedirectToAction("LogIn", "Home")); } else { GetData.SignUpError = "UserName already exists."; return(View("SignUp", GetData)); } }
public async Task <Object> CreateUser(SignUpModel model) { // Check if there is a duplicate email address foreach (var user in _context.ApplicationUsers) { if (model.Email == user.Email) { return(BadRequest(new { message = "Email already exists" })); } ; } ; var applicationUser = new ApplicationUser() { UserName = model.UserName, FullName = model.FullName, Email = model.Email }; // Create user and provide password to hash var result = await _userManager.CreateAsync(applicationUser, model.Password); // return 200 status code return(Ok(result)); }
public async Task <bool> AddUser(SignUpModel signUpModel) { User user = _dbContext.Users.FirstOrDefault(u => u.Username == signUpModel.Username); if (user == null) { var reviewer = new Reviewer { Username = signUpModel.Username, User = new User { FirstName = signUpModel.FirstName, LastName = signUpModel.LastName, MiddleName = signUpModel.MiddleName, Username = signUpModel.Username, EmailAddress = signUpModel.EmailAddress, DateOfBirth = signUpModel.DateOfBirth, PasswordHash = BCrypt.Net.BCrypt.HashPassword(signUpModel.Password) } }; _dbContext.Reviewers.Add(reviewer); await _dbContext.SaveChangesAsync(); return(true); } return(false); }
public async Task <IActionResult> SignUp(SignUpModel newUser) { if (!ModelState.IsValid) { return(View()); } Models.User user = new User { UserName = newUser.UserName, Email = newUser.Email }; if (_context.Users.Count() == 0) { user.IsSuperUser = true; } //todo: only admins can create posts. user.IsAdmin = true; var result = await _userManager.CreateAsync(user, newUser.Password); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View()); } return(RedirectToAction("Login")); }
public async Task <SignUpModel> SearchStudent(string search) { var httpClient = new HttpClient(); var taskModels = new SignUpModel(); var newUrl = _webServiceUrl + "?id=" + search; var json = JsonConvert.SerializeObject(search); HttpContent httpContent = new StringContent(json); try { //var request = new HttpRequestMessage(HttpMethod.Post, newUrl); var result = await httpClient.PostAsync(newUrl, httpContent); var content = await result.Content.ReadAsStringAsync(); taskModels = JsonConvert.DeserializeObject <SignUpModel>(content); } catch (Exception e) { taskModels.Message = e.Message; } return(taskModels); }
public ActionResult SignUp(SignUpModel signUpModel) { if (Properties.Settings.Default.AllowAccountCreate) { if (_userService.GetUserByEmail(signUpModel.User.Email) == null) { User newUser = _userService.InsertUser(signUpModel.User.Name, signUpModel.User.Email, signUpModel.Password); if (newUser != null) { String sessionId = _userService.UpdateSessionId(newUser.ID); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "DM", DateTime.UtcNow, DateTime.UtcNow.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, sessionId); String hashedTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashedTicket); Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Main")); } else { return(RedirectToAction("SignUp", new { @errorCode = "ERROR_SIGNING_UP" })); } } else { return(RedirectToAction("SignUp", new { @errorCode = "EMAIL_ADDRESS_ALREADY_TAKEN" })); } } else { return(RedirectToAction("Index", "Home")); } }
public async Task <IActionResult> Register(SignUpModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new UserModel { UserName = model.Username, Email = model.Username }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("index", "tasks")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult SignUp(SignUpModel model) { if (ModelState.IsValid) { using (DBContext context = new DBContext()) { User lookupUser = context.Users.FirstOrDefault(u => u.UserLogin == model.Login || u.UserEMail == model.Email); if (lookupUser == null) { context.Add(new User { UserLogin = model.Login, UserName = model.Name, UserPass = BCrypt.Net.BCrypt.HashPassword(model.Password), UserEMail = model.Email }); context.SaveChanges(); FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "User with the same login or email already exists"); } } } return(View(model)); }
public ActionResult UpdateUser(SignUpModel signUpModel) { if (ModelState.IsValid) { Account account = new Account(); account.UserName = signUpModel.UserName; account.UserId = signUpModel.UserId; account.MailId = signUpModel.MailId; account.Password = signUpModel.Password; account.MobileNo = signUpModel.MobileNo; // account.CreateDate = DateTime.Now; account.UpdatedDate = DateTime.Now; // account.LastLoginTime = DateTime.Now; account.Gender = signUpModel.Gender; account.Age = signUpModel.Age; account.City = signUpModel.City; accountBL.EditUser(account); return(RedirectToAction("UserDetails")); } else { ModelState.AddModelError("", "Some error occurred"); return(View()); } }
public bool SignUp(SignUpModel model) { return true; }