public IActionResult Delete(string uuid, [FromHeader] string cvr, [FromHeader] string apiKey) { if ((cvr = AuthorizeAndFetchCvr(cvr, apiKey)) == null) { return(Unauthorized()); } try { UserRegistrationExtended user = new UserRegistrationExtended() { Uuid = uuid }; userDao.Save(user, OperationType.DELETE, cvr); } catch (Exception ex) { log.Error("Failed to save User", ex); return(BadRequest(ex.Message)); } return(Ok()); }
public async Task <bool> RegisterAsync(UserRegistration user) { try { UserRegistrationExtended userToCreate = new UserRegistrationExtended(); userToCreate.Email = user.Email; userToCreate.Username = user.Username; userToCreate.RoleId = 1; userToCreate.UUID = Guid.NewGuid().ToString("N"); string tempPassword = $"{_configuration["Auth:FrontSalt"]}{user.Password}{_configuration["Auth:BackSalt"]}"; byte[] salt = GetSalt(); string hashedPassword = HashPassword(tempPassword, salt); userToCreate.Password = hashedPassword; userToCreate.Salt = salt; userToCreate.EmailValidationId = RandomString(64); await _databaseService.RegiserUserAsync(userToCreate); await _mailService.SendMail(userToCreate.Email, userToCreate.EmailValidationId); return(true); } catch (Exception e) { _logger.LogError($"Error while trying to register new user. Error:\n{e.Message}"); SentrySdk.CaptureException(e); return(false); } }
public async Task RegiserUserAsync(UserRegistrationExtended user) { _logger.LogInformation($"Registering new User with UUID: {user.UUID}."); using (var connection = _context.CreateConnection()) { var parameters = new { uuid = user.UUID, username = user.Username, email = user.Email, email_verification_id = user.EmailValidationId, password = user.Password, salt = user.Salt, created_at = DateTime.Now, id_roles = user.RoleId }; string processQuery = "INSERT INTO users (uuid,username,email,email_verification_id,password,salt,created_at,id_roles) VALUES (@uuid,@username,@email,@email_verification_id,@password,@salt,@created_at,@id_roles)"; await connection.ExecuteAsync(processQuery, parameters); } }
public IHttpActionResult Delete(string uuid) { UserRegistrationExtended user = new UserRegistrationExtended(); user.Uuid = uuid; try { userDao.Save(user, OperationType.DELETE); return(Ok(uuid)); } catch (Exception ex) { log.Error(messages.GetUserMessage(messages.DELETE_FAILED), ex); } return(BadRequest()); }