public async Task <ActionResult> Register(UserRegistrationBindingModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } User user = new User() { Firstname = model.Firstname, Lastname = model.Lastname, UserName = model.Username, Email = model.Email }; var result = await this.UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(this.View(model)); } await this.SignInManager.SignInAsync(user, false, false); return(this.RedirectToAction("Home", "Home", null)); }
public HashSet <RegistrationVerificationErrorViewModel> VerifyRegister (UserRegistrationBindingModel urbm) { HashSet <RegistrationErrorVM> revms = new HashSet <RegistrationErrorVM>(); if (urbm.Username.Length < 5 || urbm.Username.Length > 30) { revms.Add(new RegistrationErrorVM(Constants.UserNameLengthErrorMessage)); } if (urbm.FullName.Length < 5) { revms.Add(new RegistrationErrorVM(Constants.FullNameTooShortMessage)); } Regex specialSymbolrgx = new Regex(@"[!@#$%^&*,.]"); //if (urbm.Password.Length < 8 || !urbm.Password.Any(char.IsUpper) || !urbm.Password.Any(char.IsDigit) || // !specialSymbolrgx.IsMatch(urbm.Password)) //{ // revms.Add(new RegistrationErrorVM(Constants.PasswordIncorrectFormatMessage)); //} if (urbm.Password != urbm.ConfirmPassword) { revms.Add(new RegistrationErrorVM(Constants.PasswordsDoNotMatchMessage)); } return(revms); }
public async Task <IHttpActionResult> Register([FromBody] UserRegistrationBindingModel user) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var UserService = new UserService()) { var found = await UserService.FindByCredentials(user.UserName, user.Password); if (found != null) { return(BadRequest("Username is allready taken")); } await UserService.RegisterUser(user); return(Ok()); } } catch (Exception e) { return(InternalServerError(e)); } }
public IActionResult SignUp(UserRegistrationBindingModel model) { if (ModelState.IsValid) { var mapped = _mapper.Map <UserRegistrationBindingModel, UserDTO>(model); _userService.Add(mapped); Authenticate(mapped); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("SignUp")); }
public void Register(UserRegistrationBindingModel rubm) { Role role = this.data.Users.GetAll().Any() ? Role.Regular : Role.Administrator; var user = new User() { FullName = rubm.FullName, Password = rubm.Password, Username = rubm.Username, Role = role }; this.data.Users.InsertOrUpdate(user); this.data.SaveChanges(); }
public async Task <JObject> Register(string username, string email, string mobilenumber, string password, string role, double lat, double lng) { HttpClient client = new HttpClient(new NativeMessageHandler()) { BaseAddress = new Uri(APIURL) }; var user = new UserRegistrationBindingModel(); user.SiteId = GlobalConfiguration.SiteId; user.DisplayName = username; user.Email = email; user.PhoneNumber = mobilenumber; user.Password = password; user.UserRole = role; user.Lattitude = lat; user.Longitude = lng; var result = JsonConvert.SerializeObject(user); var content = new StringContent(result, Encoding.UTF8, "application/json"); if (CrossConnectivity.Current.IsConnected) { var call = client.PostAsync(APIURL + "/api/Account/Register", content); var message = await Policy .Handle <WebException>().Or <IOException>() .WaitAndRetryAsync(retryCount: 2, sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))) .ExecuteAsync(async() => await call); string data = await message.Content.ReadAsStringAsync(); if (!message.IsSuccessStatusCode) { var error = JsonConvert.DeserializeObject <JObject>(data); throw new WebException(error["Message"].ToString()); } var success = JsonConvert.DeserializeObject <JObject>(data); return(success); } else if (result == null) { throw new NullReferenceException("Results should not be null"); } else { throw new Exception("No internert connection"); } }