Esempio n. 1
0
        /// <summary>
        /// 会员登录
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static MemberAuthModel MemberLogin(string account, string password, string type, string ipaddress, string agent, string dns)
        {
            var retmem = new MemberAuthModel {
                IsSucceed = false
            };

            try
            {
                var member = MemberLogic.GetModelByWhere(new Dictionary <string, object>()
                {
                    { nameof(Member.IsDeleted), 0 },
                    { nameof(Member.UserAccount), account }
                });
                if (member == null)
                {
                    retmem.Message = "账户信息不存在";
                    return(retmem);
                }
                if (member.UserPassword != password)
                {
                    retmem.Message = "密码不正确";
                    return(retmem);
                }
                var tokenexpir = DateTime.Now.AddDays(ConfigUnit.ExpirationTimeOut).ToString();
                var logintype  = "2";
                //总共64位,4+22+5+1+32
                var token = $"{DateTime.Now.ToString("yyMM")}{Guid.NewGuid().ToString("N").Substring(0, 22)}{member.KID.ToString().PadLeft(5, '0')}{logintype}{Guid.NewGuid().ToString("N")}";

                Task.Run(() =>
                {
                    var tokenres = LogintokenLogic.Add(new Logintoken
                    {
                        Token            = token,
                        TokenExpiration  = tokenexpir,
                        CreateTime       = DateTime.Now,
                        LoginUserId      = member.KID.ToString(),
                        LoginUserType    = 2,
                        LoginUserAccount = member.UserAccount,
                        LoginResult      = "登录成功",
                        IpAddr           = ipaddress,
                        IsLogOut         = 0
                    }, new OpertionUser()
                    {
                        UserId = member?.KID.ToString()
                    });
                });
                retmem.Token      = token;
                retmem.MemberInfo = member;
                retmem.IsSucceed  = true;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, "MemberLogic/MemberLogin");
            }
            return(retmem);
        }
Esempio n. 2
0
        /// <summary>
        /// 密码登录
        /// </summary>
        /// <param name="useraccount"></param>
        /// <param name="userpsw"></param>
        /// <param name="ipaddress"></param>
        /// <param name="agent"></param>
        /// <param name="dns"></param>
        /// <returns></returns>
        public static SysLoginUser EmployeePasswordLogin(string useraccount, string userpsw, string ipaddress, string agent, string dns)
        {
            SysLoginUser res = new SysLoginUser()
            {
                IsSucceed = false
            };

            try
            {
                var psw = userpsw.ToUpper();
                var emp = EmployeeLogic.GetModelByWhere(new Dictionary <string, object>()
                {
                    { nameof(Employee.UserAcount), useraccount },
                    { nameof(Employee.IsDeleted), 0 },
                    { nameof(Employee.States), 0 }
                });
                if (emp.UserPassword.ToUpper() != psw)
                {
                    return(res);
                }
                #region 获取menu操作列表

                res.UserAuthorMenu = Comlogic.GetMenulistByUserid(emp.KID);
                // res.UserAuthorMenu = new UserAuthorMenu() { IsSucceed = true };

                #endregion

                var logintype = "1";
                //总共64位,4+22+5+1+32
                var token      = $"{DateTime.Now.ToString("yyMM")}{Guid.NewGuid().ToString("N").Substring(0, 22)}{emp.KID.ToString().PadLeft(5, '0')}{logintype}{Guid.NewGuid().ToString("N")}";
                var tokenexpir = DateTime.Now.AddDays(ConfigUnit.ExpirationTimeOut).ToString();
                res.TokenExpiration = tokenexpir;
                var tokenres = LogintokenLogic.Add(new Logintoken
                {
                    Token            = token,
                    TokenExpiration  = tokenexpir,
                    CreateTime       = DateTime.Now,
                    LoginUserId      = emp.KID.ToString(),
                    LoginUserType    = 1,
                    LoginUserAccount = emp.UserAcount,
                    LoginResult      = "登录成功",
                    IpAddr           = ipaddress,
                    IsLogOut         = 0
                }, new OpertionUser()
                {
                    UserId = emp?.KID.ToString()
                });


                res.IsSucceed = res.UserAuthorMenu.IsSucceed;
                res.Message   = res.UserAuthorMenu.IsSucceed ? "登录成功菜单获取成功" : res.UserAuthorMenu.Message;
                if (res.UserAuthorMenu.IsSucceed)
                {
                    res.Token           = token;
                    res.Model           = emp;
                    res.TokenExpiration = tokenexpir;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, "登录出错", LogLevel.D错误事件);
                res.IsSucceed = false;
            }
            return(res);
        }