Example #1
0
        public async Task <string> ValidateUserPassword(string user)
        {
            var     userRabbitMq = Newtonsoft.Json.JsonConvert.DeserializeObject <UserDto>(user);
            UserDto dbUser       = await _userDal.Find(userRabbitMq.Uuid);

            bool passwordCorrect = _securityLogic.VerifyPassword(userRabbitMq.Password, dbUser?.Password);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(passwordCorrect));
        }
Example #2
0
        public IResult Add(User user)
        {
            var result = _userDal.Find(p => p.Email == user.Email);

            if (result != null)
            {
                return(new ErrorResult("This User already added"));
            }
            _userDal.Add(user);
            return(new SuccessResult("Your User successfully posted"));
        }
Example #3
0
        /// <summary>
        /// Checks if the credentials are correct and returns an jwt and refresh token if password is correct
        /// </summary>
        /// <param name="login">The username and password</param>
        /// <returns>An jwt and refresh token if password is correct, if not correct null is returned</returns>
        public async Task <LoginResultViewmodel> Login(Login login)
        {
            UserDto dbUser = await _userDal.Find(login.Username);

            if (dbUser == null)
            {
                throw new UnauthorizedAccessException();
            }

            bool userIsDisabled = _rpcClient.Call <bool>(dbUser.Uuid, RabbitMqQueues.DisabledExistsUserQueue);

            if (userIsDisabled)
            {
                throw new DisabledUserException();
            }

            bool passwordCorrect = _securityLogic.VerifyPassword(login.Password, dbUser.Password);

            if (!passwordCorrect)
            {
                throw new UnauthorizedAccessException();
            }

            if (login.LoginCode > 99999 && login.LoginCode < 1000000 && login.SelectedAccountRole != AccountRole.Undefined)
            {
                return(await LoginWithSelectedAccount(login, dbUser));
            }

            if (dbUser.AccountRole > AccountRole.User)
            {
                return(await HandleMultipleAccountRolesLogin(dbUser));
            }

            AuthorizationTokensViewmodel tokens = await _jwtLogic.CreateJwt(dbUser);

            return(new LoginResultViewmodel
            {
                Jwt = tokens.Jwt,
                RefreshToken = tokens.RefreshToken
            });
        }
        public async Task <List <UserDto> > All()
        {
            List <Guid> disabledUserUuidCollection = await _disabledUserDal.All();

            return(await _userDal.Find(disabledUserUuidCollection));
        }
Example #5
0
 /// <summary>
 /// Finds all users which match the uuid in the collection
 /// </summary>
 /// <param name="uuidCollection">The uuid collection</param>
 /// <returns>The found users, null if nothing is found</returns>
 public async Task <List <UserDto> > Find(List <Guid> uuidCollection)
 {
     return(await _userDal.Find(uuidCollection));
 }
Example #6
0
 public User GetByUserId(int id)
 {
     return(_userDal.Find(x => x.UserID == id));
 }