示例#1
0
        public async Task <UserModel> Register(RegisterUserModel registerModel)
        {
            if (await _userRepository.GetUserByEmail(registerModel.Email) != null)
            {
                return(null);
            }

            PasswordObject passworObjecth = CryptographyService.GetHash(registerModel.Password);

            UserRequest user = new UserRequest()
            {
                FirstName    = registerModel.FirstName,
                SecondName   = registerModel.SecondName,
                Email        = registerModel.Email,
                PasswordHash = passworObjecth.PasswordHash,
                Salt         = passworObjecth.Salt,
                Role         = defaultRole
            };

            int userId = await _userRepository.UpsertUser(user);

            UserModel userModel = new UserModel(
                userId,
                user.FirstName,
                user.SecondName,
                user.Email,
                user.Role
                );

            return(userModel);
        }
示例#2
0
        public async Task <UserModel> Login(string email, string password)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                return(null);
            }
            else
            {
                UserResponse user = await _userRepository.GetUserByEmail(email);

                if (user == null)
                {
                    return(null);
                }

                PasswordObject passwordObject = CryptographyService.GetHash(password, user.Salt);

                if (ByteArraysCompaire(passwordObject.PasswordHash, user.PasswordHash))
                {
                    UserModel userModel = new UserModel(
                        user.Id,
                        user.FirstName,
                        user.LastName,
                        user.Email,
                        user.Role
                        );
                    return(userModel);
                }

                return(null);
            }
        }