コード例 #1
0
        private Users RegisterUser(UserRegistrationRequestDetails registrationDetailsRequest)
        {
            Users userToReturnAfterSuccessfullCreation = null;

            Users newUser = new Users();

            newUser.FirstName  = registrationDetailsRequest.FirstName;
            newUser.LastName   = registrationDetailsRequest.LastName;
            newUser.MiddleName = registrationDetailsRequest.MiddleName;

            newUser.Username = registrationDetailsRequest.Username;
            newUser.Email    = registrationDetailsRequest.Email;

            string applicationSecretSolt     = this._config["Jwt:ExtraApplicationPasswordsEncryptionInAdditionToRandomSalts"];
            int    randomGeneratedSoltLength = int.Parse(this._config["Jwt:CryptographyProcessorRandomSoltLength"]);
            string randomGeneratedSoltForPasswordEncryptionAndDatabaseSaving = CryptographyProcessor.CreateSalt(randomGeneratedSoltLength);

            string encryptedHashedPassword = CryptographyProcessor.GenerateHash(
                registrationDetailsRequest.Password,
                randomGeneratedSoltForPasswordEncryptionAndDatabaseSaving,
                applicationSecretSolt);

            newUser.EcryptedPassword     = encryptedHashedPassword;
            newUser.EncryptionRandomSalt = randomGeneratedSoltForPasswordEncryptionAndDatabaseSaving;

            newUser.BirthDate        = registrationDetailsRequest.BirthDate;
            newUser.RegistrationDate = DateTime.UtcNow;

            newUser.CountryCode = registrationDetailsRequest.CountryCode;
            newUser.CountryName = registrationDetailsRequest.CountryName;

            //Users userToReturnAfterSuccessfullCreation = Business_Logic_Layer_Facade.Instance.Users_InsertUser(newUser);

            return(userToReturnAfterSuccessfullCreation);
        }
コード例 #2
0
        public IActionResult Register([FromBody] UserRegistrationRequestDetails registrationDetailsRequest)
        {
            IActionResult response = Unauthorized();

            var user = this.RegisterUser(registrationDetailsRequest);

            if (user != null)
            {
                var tokenString = GenerateJSONWebToken(user);
                response = Ok(new { token = tokenString });
            }

            return(response);
        }