/// <summary> /// 申请登陆 /// </summary> /// <param name="name">账户名</param> /// <param name="password">登陆密码</param> /// <param name="effectiveTime">保存时间</param> /// <param name="isAdmin">是否管理员登陆</param> /// <returns></returns> private EnumLoginState ApplyLogin(string name, string password, int effectiveTime, bool isAdmin) { if (string.IsNullOrEmpty(name)) { return(EnumLoginState.AccountError); } Users user = new Users(); if (name.Contains("@")) { user = UsersAccessor.GetByEmail(name); } else { user = UsersAccessor.GetByMobile(name); } if (user == null) { return(EnumLoginState.AccountError); } if (!string.Equals(user.Password, Strings.PasswordEncrypt(password))) { return(EnumLoginState.PasswordError); } UserId = user.UserId; Password = user.Password; Username = user.Username; Mobile = user.Mobile; Email = user.Email; CurrentLoginTime = DateTime.Now; PermissionCode = user.PermissionCode; SaveLogin(this, effectiveTime); SessionBag.Refresh(); SessionBag.CopyValue(); //更新用户登陆次数 //更新在线数据 return(EnumLoginState.Succeed); }
/// <summary> /// 初始化cookie读取 /// </summary> private void Initialize() { var userCookie = Cookies.Get(Context, Keys.UserCookie); if (userCookie.Count == 0) { UserId = 0; token = string.Empty; Username = "******"; } else { try { UserId = long.Parse(userCookie["uid"]); token = userCookie["token"]; } catch { Logout(); } SessionBag.CopyValue(); ValidateCookie(); } }