/// <summary>
        /// 设置登录标记
        /// </summary>
        /// <param name="commandResult"></param>
        public static void SetLogin(HttpContext httpContext, UserLoginCommandResult commandResult)
        {
            httpContext.Session.SetString(Global._session_server, commandResult.UserInfo.user_account);
            // 指定身份认证类型
            var identity = new ClaimsIdentity("Forms");
            // 用户名称
            var tempC = new Claim(ClaimTypes.Sid, commandResult.UserInfo.user_account);

            identity.AddClaim(tempC);
            var principal = new ClaimsPrincipal(identity);

            // 登陆
            httpContext.SignInAsync(Global._auth, principal, new AuthenticationProperties
            {
                IsPersistent = true
            });
        }
Ejemplo n.º 2
0
        public CommandResult AuthenticateUser(string userName, string password, string phoneNumber)
        {
            var userLogin = UserLogin().FirstOrDefault(t => t.User_PersonId.PrimaryPhoneNumber == phoneNumber);

            if (userLogin == null)
            {
                throw new InvalidOperationException("Username or Password Is Incorrect!");
            }
            if (userLogin.User_PersonId.IsUserActivated != "Y" ||
                userLogin.User_PersonId.StatusId != Utility.StatusEnabled)
            {
                throw new InvalidOperationException("User is not activated!");
            }
            var result = Utility.ValidateHashPassword(password, userLogin?.CurrentPassword);

            if (!result)
            {
                throw new InvalidOperationException("Username or Password Is Incorrect!");
            }
            if (userLogin.RequirePasswordChange == "Y")
            {
                return(Utility.CommandSuccess(new UserLoginCommandResult {
                    IsLoginSuccess = true, RequirePasswordChange = "Y"
                }));
            }
            if (userLogin?.User_PersonId.IsUserActivated != "Y" ||
                userLogin.User_PersonId.StatusId != Utility.StatusEnabled)
            {
                throw new InvalidOperationException("Username or Password Is Incorrect!");
            }
            var userLoginCommandResult = new UserLoginCommandResult
            {
                IsLoginSuccess        = true,
                RequirePasswordChange = userLogin.RequirePasswordChange,
                IsUserActivated       = userLogin.User_PersonId.IsUserActivated,
                SecurityToken         = Utility.GetSecurityToken(),
                UserId      = userLogin.PersonId,
                UserLoginId = userLogin.UserLoginId,
                UserTypeId  = userLogin.UserRoleUserLogin_UserLoginId.FirstOrDefault()?.RoleTypeId
            };

            return(Utility.CommandSuccess(userLoginCommandResult));
        }
Ejemplo n.º 3
0
        //public CommandResult CreateJobOffer(string jobPostId, string modelId, string userLoginId)
        //{
        //    var jobOffer = AddJobOffer(jobPostId, modelId, userLoginId);
        //    return Utility.CommandSuccess(jobOffer.JobOfferId);
        //}

        //internal JobOffer AddJobOffer(string jobPostId, string modelId, string userLoginId)
        //{
        //    var jobOffer = new JobOffer
        //    {
        //        JobOfferId = Utility.GetId(),
        //        OfferedUserId = modelId,
        //        JobPostId = jobPostId,
        //        UserLoginId = userLoginId
        //    };
        //    JobOffer().Add(jobOffer);
        //    return jobOffer;
        //}

        public CommandResult ActivateUserAccount(string userName, string verificationCode, string phoneNumber, string newPassword)
        {
            //var userLogin = UserLogin().FirstOrDefault(t => t.UserName == userName);
            //if (userLogin == null) throw new InvalidOperationException("User not found!");
            //var user = User().Find(userLogin.PersonId);
            //if (user.IsUserActivated == "Y")
            //    throw new InvalidOperationException("User is already activated!");
            //if (verificationCode != user.VerificationCode)
            //    throw new InvalidOperationException("Your verification code is Incorrect!");
            //user.IsUserActivated = "Y";
            //user.StatusId = Utility.StatusEnabled;
            //User().UpdateEntity(user);
            //userLogin.RequirePasswordChange = "N";
            //userLogin.CurrentPassword = Utility.HashPassword(newPassword);
            //UserLogin().UpdateEntity(userLogin);
            var user = User().FirstOrDefault(t => t.PrimaryPhoneNumber == phoneNumber);

            if (user == null)
            {
                throw new InvalidOperationException("User not found!");
            }
            user.IsUserActivated  = "Y";
            user.StatusId         = Utility.StatusEnabled;
            user.VerificationCode = verificationCode;
            User().UpdateEntity(user);
            var userLogin = UserLogin().FirstOrDefault(t => t.PersonId == user.PersonId);

            userLogin.CurrentPassword       = Utility.HashPassword(newPassword);
            userLogin.RequirePasswordChange = "N";
            UserLogin().UpdateEntity(userLogin);
            var userLoginCommandResult = new UserLoginCommandResult
            {
                IsLoginSuccess        = true,
                RequirePasswordChange = userLogin.RequirePasswordChange,
                IsUserActivated       = userLogin.User_PersonId.IsUserActivated,
                SecurityToken         = Utility.GetSecurityToken(),
                UserId      = userLogin.PersonId,
                UserLoginId = userLogin.UserLoginId,
                UserTypeId  = userLogin.UserRoleUserLogin_UserLoginId.FirstOrDefault()?.RoleTypeId
            };

            return(Utility.CommandSuccess(userLoginCommandResult));
        }
Ejemplo n.º 4
0
        public CommandResult ChangeUserPassword(string userName, string currentPassword, string newPassword)
        {
            var userLogin = UserLogin().FirstOrDefault(t => t.UserName == userName);

            if (userLogin == null || !Utility.ValidateHashPassword(currentPassword, userLogin.CurrentPassword))
            {
                throw new InvalidOperationException("Username or Password Is Incorrect!");
            }
            userLogin.CurrentPassword       = Utility.HashPassword(newPassword);
            userLogin.RequirePasswordChange = "N";
            UserLogin().Update(userLogin);
            var result = new UserLoginCommandResult
            {
                UserId        = userLogin.User_PersonId.PersonId,
                UserLoginId   = userLogin.UserLoginId,
                SecurityToken = Utility.GetSecurityToken()
            };

            return(Utility.CommandSuccess(result));
        }