Esempio n. 1
0
        /// <summary>
        /// Hàm này gọi từ trang tôi quên mật khẩu.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BaseResponse ChangePwd(ChangePwdResquest request)
        {
            return Execute(_repository, r =>
            {
                var response = new BaseResponse();

                var requestData = _requestPasswordRepository.GetByRefKey(request.KeyRef);

                if (requestData == null)
                {
                    response.Success = false;
                    response.Messages.Add("BadRequest");//Res key
                    return response;
                }

                var beUser = _cacheHelper.GetAllBeUsers().FirstOrDefault(i => i.Email == requestData.Email.ToStr().Trim().ToLower());
                if (beUser == null)
                {
                    response.Success = false;
                    response.Messages.Add("UnableFindUser");//Res key
                    return response;
                }

                request.UserId = beUser.Id;
                request.NewPassword = SimpleHash.ComputeHash(request.NewPassword, SiteSettings.HashAlgorithm, null);

                r.ChangePwd(request);

                _requestPasswordRepository.Delete(requestData.Id);

                _cacheHelper.ClearGetBeUser(beUser.Id);

                return response;
            });
        }
Esempio n. 2
0
        public BaseResponse ChangePwd(ChangePwdResquest request)
        {
            using (var db = DbContext)
            {
                var entityDb = new Entity.BeUser { Id = request.UserId, HashPassword = request.NewPassword };
                db.BeUsers.Attach(entityDb);
                db.Entry(entityDb).Property(o => o.HashPassword).IsModified = true;
                db.SaveChanges();
            }

            return new BaseResponse();
        }
Esempio n. 3
0
        /// <summary>
        /// Hàm này gọi từ trang change password khi user đã login
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BaseResponse SaveChangePassword(ChangePwdResquest request)
        {
            return Execute(_repository, r =>
            {
                var response = new BaseResponse();
                var beUser = _cacheHelper.GetBeUser(request.UserId);

                if (beUser == null)
                {
                    response.Success = false;
                    response.Messages.Add("UnableFindUser");//Res key
                    return response;
                }

                if (!SimpleHash.VerifyHash(request.Password, SiteSettings.HashAlgorithm, beUser.HashPassword))
                {
                    response.Messages.Add("PwdIncorrect");
                    response.Success = false;
                    return response;
                }

                request.NewPassword = SimpleHash.ComputeHash(request.NewPassword, SiteSettings.HashAlgorithm, null);

                r.ChangePwd(request);

                _cacheHelper.ClearGetBeUser(beUser.Id);

                return response;
            });
        }