public IHttpActionResult POSTCreateUser(UserModel user) { if (_authRepository.IsEmailUnique(user.Email)) { return(BadRequest("email already taken")); } var appUser = new ApplicationUser { Email = user.Email, UserName = user.Email }; var res = _authRepository.Add(appUser, user.Password); if (!res.Succeeded) { return(BadRequest(res.Errors.ToList()[0])); } var identity = _authRepository.FindUser(user.Email, user.Password); _authRepository.SetRole(identity.Id, Roles.user); EmitCommand(user, Operation.Create, identity.Id); return(Ok(identity.Id)); }
public void Register(UserToCreateDto userToCreate) { userToCreate.Username = userToCreate.Username.ToLower(); if (_authRepository.Any(x => x.Username == userToCreate.Username)) { throw new Exception("Já existe alguem com esse Nome de Usuário."); } var userToAdd = _mapper.Map <User>(userToCreate); CreatePasswordHash(userToCreate.Password, out var passwordHash, out var passwordSalt); userToAdd.LocalidadeId = GetLocalizacao(userToCreate.Cep).Result; userToAdd.PasswordHash = passwordHash; userToAdd.PasswordSalt = passwordSalt; _authRepository.Add(userToAdd); if (!Commit()) { throw new Exception("Houve algum erro ao salvar no Banco de Dados."); } }
public async Task <IActionResult> SignUp([FromForm] User user) { var isValid = _service.ValidateUser(user, true, -1); if (isValid.Count == 0) { var createdUser = await _service.Add(user); if (createdUser.UserType == "teacher") { _serviceProfession.getProfessionById((int)createdUser.IdProfession); _serviceTeacherClass.GetConnectedClassroomsByIdUser(user.Id); } else if (createdUser.UserType == "student") { _serviceClass.getClassById((int)createdUser.IdClassroom); } createdUser.PasswordHash = ""; createdUser.PasswordSalt = ""; Auth auth = new Auth(_config); var tokenString = auth.GenerateJSONWebToken(createdUser.Email, createdUser.DateJoined); return(Ok(new { success = true, user = createdUser, token = tokenString, expiresIn = 3600 * 24 })); } return(Json(new { success = false, errors = isValid })); }
public async Task <IActionResult> GetEmail(EmailDto emailDto) { Random random = new Random(); int number = random.Next(100000, 999999); MailService.SendMail("Confirmation Mail", emailDto.Email, "Code: <br>" + number); var emailCode = new EmailCode() { Email = emailDto.Email, Code = number }; _authRepo.Add(emailCode); if (await _authRepo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to send the code")); }
/// <summary> /// Addes mail to the auth table in the database. /// </summary> /// <param name="userEmail"></param> /// <returns></returns> private async Task AddUserToAuthDb(string email, string password, string userId) { try { await _authRepository.Add(new AuthModel(email, password, userId)); } catch (Exception e) { //TODO: log throw new AddAuthToDbException(e.Message); } }
public void Create(List <RefreshToken> lstObj) { if (lstObj == null) { return; } foreach (var obj in lstObj) { _repository.Add(obj); } _unitOfWork.Commit(); }
public void Handle(Register command) { byte[] passwordHash, passwordSalt; CreatePasswordHash(command.Password, out passwordHash, out passwordSalt); var user = new User { Username = command.Username, PasswordHash = passwordHash, PasswordSalt = passwordSalt }; _authRepository.Add(user); _authRepository.Save(); }
public async Task <User> Register(User user, string password) { try { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; _authRepository.Add(user); await _unitOfWork.Commit(); return(user); } catch (Exception ex) { throw ex; } }
public async Task <UserEntity> Register(string username, string password) { var user = new UserEntity() { Username = username }; byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; await _authRepository.Add(user); // Adding the user to context of users. return(user); }
public IActionResult Add([FromBody] Kisiler newdata) { if (newdata == null) { return(Ok(_ControllersHelper.notfound("data is null"))); } _authRepository.Add(newdata); //////////////////////////////////////// var res = _authRepository.SaveAll(); if (res.OK) { return(Ok(newdata)); //return CreatedAtRoute("Detail", new { identifier }, newdata); } else { return(BadRequest("başarısız?! " + res.ERR)); } }
public IActionResult Register([FromBody] RegisterInformation registrationInformation) { try { var salt = _cryptoService.GenerateSalt(); User user = new User { Salt = salt, Email = registrationInformation.Email, Password = _cryptoService.HashSha512(registrationInformation.Password, salt), Active = true }; _repository.Add(user); } catch (Exception e) { return(new NoContentResult()); } return(new ContentResult()); }
public async Task <User> Create(User user, string password) { if (string.IsNullOrWhiteSpace(password)) { throw new Exception("Password is required"); } if (await _authRepository.GetUserByEmailAsync(user.Email) != null) { throw new Exception("Username \"" + user.Email + "\" is already taken"); } CreatePasswordHash(password, out var passwordHash, out var passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; _authRepository.Add(user); await _unitOfWork.Complete(); return(user); }
public Message RegisterUser(RegisterViewModel registerViewModel) { Message model = new Message(); try { registerViewModel.Status = true; registerViewModel.RoleId = 1; var register = registerViewModel.ToDalEntity(); _authRepository.Add(register); _authRepository.SaveChanges(); model.StatusCode = 200; model.Status = "User Registration Successful"; } catch (Exception ex) { model.StatusCode = 200; model.Status = "User Registration Successful"; } return(model); }
public async Task <IActionResult> Post([FromBody] Vehicle vehicle) { return(Ok(await repository.Add(vehicle))); }
public User Register(User user) { user.Password = HashMD5.Create(user.Password); return(_authRepository.Add(user)); }
public async Task <IActionResult> Post([FromBody] User user) { return(Ok(await repository.Add(user))); }
public async Task <IActionResult> Post([FromBody] Cart cart) { return(Ok(await repository.Add(cart))); }