public async Task <IActionResult> Post([FromBody] DTOs.UserCredentials credentials)
        {
            Mdls.User user = await userRepository.GetUserByNameOrEmail(credentials.Name);

            if (user != null && user.Active)
            {
                string Password = decryptionProvider.Decrypt(user.Password, user.EncryptionKey);

                if (credentials.Password == Password)
                {
                    Dictionary <string, Func <Mdls.User, object> > contract = new Dictionary <string, Func <Mdls.User, object> >()
                    {
                        { ClaimKeys.USER_ID, (Mdls.User u) => u.id },
                        { ClaimKeys.ROLE, (Mdls.User u) => (int)u.Role }
                    };

                    tokenGenerator.Create(user, contract);
                    string token = tokenProvider.WriteToken <Mdls.User>(tokenGenerator);


                    return(Ok(new { token = token }));
                }
            }



            return(BadRequest(new DTOs.Error("Error On User Credentials")));
        }
Exemplo n.º 2
0
        public async Task <ActionResponse> UpdatePassword([FromBody] PasswordEdit passwordRequest)
        {
            string userId = authenticationCurrentContext.CurrentUser;

            Mdls.User user = await userRepository.Get(userId);

            if (user != null)
            {
                #region Verify Password Match
                string originalPassword = decryptionProvider.Decrypt(user.Password, user.EncryptionKey);
                bool   verified         = passwordRequest.CurrentPassword == originalPassword;
                #endregion

                if (verified)
                {
                    string encryptedPassword = encryptionProvider.Encrypt(passwordRequest.Password);
                    string encryptionKey     = encryptionProvider.EncryiptionKey;

                    bool updated = await userRepository.UpdatePassword(userId, encryptedPassword, encryptionKey);

                    return(new ActionResponse
                    {
                        State = updated
                    });
                }
            }

            return(new ActionResponse
            {
                State = false
            });
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetUser(string userId)
        {
            Mdls.User user = await userRepository.Get(userId);

            DTOs.User userClient = mapper.Map <Mdls.User, DTOs.User>(user);

            return(Ok(userClient));
        }
Exemplo n.º 4
0
        public async Task <DTOs.User> GetMe()
        {
            string userId = authenticationCurrentContext.CurrentUser;

            Mdls.User user = await userRepository.Get(userId);

            DTOs.User userClient = mapper.Map <Mdls.User, DTOs.User>(user);

            return(userClient);
        }
Exemplo n.º 5
0
        public async Task <DTOs.User> GetUser(string userId)
        {
            if (cacheProvider.DoesKeyExist <DTOs.User>(userId))
            {
                DTOs.User user = cacheProvider.Get <DTOs.User>(userId);
                return(user);
            }
            else
            {
                Mdls.User userdisplay = await userRepository.Get(userId);

                DTOs.User user = mapper.Map <Mdls.User, DTOs.User>(userdisplay);
                cacheProvider.Set <DTOs.User>(userId, user);
                return(user);
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResponse> UpdateUserPassword([FromBody] PasswordChangeBasedRequest request)
        {
            bool completed = false;


            Mdls.User user = await userRepository.GetUserByEmail(request.email);

            if (user != null)
            {
                string encryptedPassword = encryptionProvider.Encrypt(request.password);
                string encryptionKey     = encryptionProvider.EncryiptionKey;

                bool updated = await userRepository.UpdatePassword(user.id, encryptedPassword, encryptionKey);

                completed = updated;
            }

            return(new ActionResponse
            {
                State = completed
            });
        }