示例#1
0
        public UserLoginResponse Login(String username, String password, HttpRequest request)
        {
            try
            {
                VPBLL.Users.UsersHelper helper = new VPBLL.Users.UsersHelper();
                List<VPBLL.Users.ABiAdminUsers> list = helper.getUsers(username, password);

                if (list != null && list.Count > 0 && list[0].Status)
                {
                    VPBLL.Users.ABiAdminUsers user = list[0];

                    if (user.LoginStatus == "1" && user.LastLogin >= DateTime.Now.AddMinutes(-15) && user.IPAddress != request.UserHostAddress)
                    {
                        return new UserLoginResponse()
                        {
                            ResponseCode = (int)APIResponseCode.Login_Account_Is_Logining,
                            ResponseMessage = "该帐号处于登陆状态",
                            UserID = 0
                        };
                    }
                    else
                    {
                        VPBLL.Roles.AdminUsersRolesHelper roleHelper = new VPBLL.Roles.AdminUsersRolesHelper();
                        List<VPBLL.Roles.ABiAdminUsersRoles> roleList = roleHelper.getUsersRolesByUserID(user.ABi_Admin_Users_ID);
                        if (roleList != null && roleList.Count > 0)
                        {

                            user.LoginStatus = "1";
                            user.LastLogin = DateTime.Now;
                            user.IPAddress = request.UserHostAddress;
                            helper.updateUsersLastLogin(user);

                            return new UserLoginResponse()
                            {
                                ResponseCode = (int)APIResponseCode.Success,
                                ResponseMessage = "Success",
                                UserID = user.ABi_Admin_Users_ID,
                                RoleID = roleList[0].ABi_Admin_Roles_ID
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return new UserLoginResponse()
                {
                    ResponseCode = (int)APIResponseCode.System_Error,
                    ResponseMessage = ex.Message,
                    UserID = 0
                };
            }

            return new UserLoginResponse() {
                ResponseCode = (int)APIResponseCode.Login_Failed,
                ResponseMessage = "登录失败",
                UserID = 0
            };
        }