示例#1
0
        public LoginResult Do(PassportLoginRequest model)
        {
            var result = new LoginResult();

            try
            {
                model.Trim();
                //获取应用信息
                var appInfo = _appInfoService.Get(model.AppKey);
                if (appInfo == null)
                {
                    throw  new Exception("应用不存在");
                }
                //获取用户信息
                User userInfo = null;
                if (model.Account == Define.SYSTEM_USERNAME)
                {
                    userInfo = new User
                    {
                        Id       = Guid.Empty.ToString(),
                        Account  = Define.SYSTEM_USERNAME,
                        Name     = "超级管理员",
                        Password = Define.SYSTEM_USERPWD
                    };
                }
                else
                {
                    userInfo = _app.FirstOrDefault(u => u.Account == model.Account);
                }

                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (userInfo.Password != model.Password)
                {
                    throw new Exception("密码错误");
                }

                if (userInfo.Status != 0)
                {
                    throw new Exception("账号状态异常,可能已停用");
                }

                var currentSession = new UserAuthSession
                {
                    Account    = model.Account,
                    Name       = userInfo.Name,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    AppKey     = model.AppKey,
                    CreateTime = DateTime.Now
                                 //    , IpAddress = HttpContext.Current.Request.UserHostAddress
                };

                //创建Session
                _cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10));

                result.Code      = 200;
                result.ReturnUrl = appInfo.ReturnUrl;
                result.Token     = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }

            return(result);
        }
示例#2
0
        public LoginResult Do(PassportLoginRequest model)
        {
            var result = new LoginResult();

            try
            {
                model.Trim();
                //获取应用信息
                var appInfo = _appInfoService.Get(model.AppKey);
                if (appInfo == null)
                {
                    throw  new Exception("应用不存在");
                }
                //获取用户信息
                User userInfo = null;
                if (model.Account == "System")
                {
                    userInfo = new User
                    {
                        Id       = Guid.Empty.ToString(),
                        Account  = "System",
                        Name     = "超级管理员",
                        Password = "******"
                    };
                }
                else
                {
                    userInfo = _app.FindSingle(u => u.Account == model.Account);
                }

                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (userInfo.Password != model.Password)
                {
                    throw new Exception("密码错误");
                }

                var currentSession = new UserAuthSession
                {
                    Account    = model.Account,
                    Name       = userInfo.Name,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    AppKey     = model.AppKey,
                    CreateTime = DateTime.Now
                                 //    , IpAddress = HttpContext.Current.Request.UserHostAddress
                };

                //创建Session
                _objCacheProvider.Create(currentSession.Token, currentSession, DateTime.Now.AddDays(10));

                result.Code      = 200;
                result.ReturnUrl = appInfo.ReturnUrl;
                result.Token     = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }

            return(result);
        }
示例#3
0
        public static LoginResult Parse(PassportLoginRequest model)
        {
            var result = new LoginResult();

            try
            {
                model.Trim();
                //获取应用信息
                var appInfo = new AppInfoService().Get(model.AppKey);
                if (appInfo == null)
                {
                    throw  new Exception("应用不存在");
                }
                //获取用户信息
                User userInfo = null;
                if (model.Account == "System")
                {
                    userInfo = new User
                    {
                        Id       = Guid.Empty.ToString(), //TODO:可以根据需要调整
                        Account  = "System",
                        Name     = "超级管理员",
                        Password = Infrastructure.Md5.Encrypt("123456")
                    };
                }
                else
                {
                    var usermanager = (UserManagerApp)DependencyResolver.Current.GetService(typeof(UserManagerApp));
                    userInfo = usermanager.Get(model.Account);
                }
                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (userInfo.Password.ToLower() != model.Password.ToLower())
                {
                    throw new Exception("密码错误");
                }
                var currentSession = new UserAuthSession
                {
                    Account    = model.Account,
                    Name       = userInfo.Name,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    AppKey     = model.AppKey,
                    CreateTime = DateTime.Now,
                    IpAddress  = HttpContext.Current.Request.UserHostAddress
                };
                //创建Session
                new ObjCacheProvider <UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddDays(10));

                result.Code      = 200;
                result.ReturnUrl = appInfo.ReturnUrl;
                result.Token     = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }

            return(result);
        }
示例#4
0
        public static LoginResult Parse(PassportLoginRequest model)
        {
            var result = new LoginResult();

            try
            {
                model.Trim();
                //获取应用信息
                var appInfo = new AppInfoService().Get(model.AppKey);
                if (appInfo == null)
                {
                    throw  new Exception("应用不存在");
                }
                //获取用户信息
                User userInfo = null;
                if (model.UserName == "System")
                {
                    userInfo = new User
                    {
                        Id       = Guid.Empty,
                        Account  = "System",
                        Name     = "超级管理员",
                        Password = "******"
                    };
                }
                if (model.UserName == "guest")
                {
                    userInfo = new User
                    {
                        Id       = Guid.Empty,
                        Account  = "guest",
                        Name     = "游客",
                        Password = ""
                    };
                }
                else if (model.UserName != "System")
                {
                    var usermanager = (UserManagerApp)DependencyResolver.Current.GetService(typeof(UserManagerApp));
                    userInfo = usermanager.Get(model.UserName);
                }

                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (userInfo.Account != "guest")
                {
                    if (userInfo.Password != model.Password)
                    {
                        throw new Exception("密码错误");
                    }
                }

                var currentSession = new UserAuthSession
                {
                    UserName   = model.UserName,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    AppKey     = model.AppKey,
                    CreateTime = DateTime.Now,
                    IpAddress  = HttpContext.Current.Request.UserHostAddress
                };

                //创建Session
                new ObjCacheProvider <UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddDays(10));

                result.Success   = true;
                result.ReturnUrl = appInfo.ReturnUrl;
                result.Token     = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Success  = false;
                result.ErrorMsg = ex.Message;
            }

            return(result);
        }