Ejemplo n.º 1
0
        public (bool, ESysUserInfo) Login(string UserName, string Pwd)
        {
            string       sql  = "select UserID,UserName,Pwd,Mobile,OpenId,Status from Sys_UserInfo where UserName=@UserName and Pwd=@Pwd";
            ESysUserInfo user = _context.QueryFirstOrDefault <ESysUserInfo>(sql, new { UserName = UserName, Pwd = Pwd });

            return(user != null, user);
        }
Ejemplo n.º 2
0
        //public string LoginUserMenu()
        //{
        //    string loginMenu = string.Empty;
        //    ClaimsIdentity claimsIdentity = _HttpContextAccessor.HttpContext.User.Identity as ClaimsIdentity;
        //    if (claimsIdentity.HasClaim(c => c.Type == ClaimTypes.AuthorizationDecision))
        //    {
        //        loginMenu = claimsIdentity.FindFirst(ClaimTypes.AuthorizationDecision).Value;
        //    }
        //    return loginMenu;
        //}

        public ESysUserInfo LoginAccount()
        {
            ClaimsIdentity claimsIdentity = _HttpContextAccessor.HttpContext.User.Identity as ClaimsIdentity;

            if (_LoginAccount == null)
            {
                _LoginAccount = claimsIdentity.FindFirst(ClaimTypes.UserData).Value.ToObject <ESysUserInfo>();
            }

            return(_LoginAccount);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CerateOrEdit([FromBody] ESysUserInfo eSysUserInfo)
        {
            bool flag = false;

            try
            {
                if (eSysUserInfo.UserID == 0)
                {
                    using (var uow = _uowFactory.Create())
                    {
                        flag = await _SysUserInfoRepository.AddAsync(eSysUserInfo);

                        uow.SaveChanges();
                    }
                    if (flag)
                    {
                        return(Ok(new { status = true, message = "success" }));
                    }
                    else
                    {
                        return(Ok(new { status = false, message = "error" }));
                    }
                }
                else
                {
                    using (var uow = _uowFactory.Create())
                    {
                        flag = await _SysUserInfoRepository.UpdateAsync(eSysUserInfo);

                        uow.SaveChanges();
                    }
                    if (flag)
                    {
                        return(Ok(new { status = true, message = "success" }));
                    }
                    else
                    {
                        return(Ok(new { status = false, message = "error" }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { status = false, message = ex.Message }));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Signin(string username, string password, string remember)
        {
            EResult re = new EResult()
            {
                StatusCode = -1, Status = false, Message = "fault"
            };

            try
            {
                if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                {
                    string pwd5 = MD5Util.Get32MD5Two(password);
                    (bool, ESysUserInfo)reLogin = _SysUserInfoRepository.Login(username, pwd5);
                    if (reLogin.Item1)
                    {
                        if (reLogin.Item2.Status == 1)
                        {
                            ESysUserInfo _user = reLogin.Item2;

                            IList <Claim> claims = new List <Claim>();

                            claims.Add(new Claim(ClaimTypes.Name, _user.UserName, ClaimValueTypes.String, LoginManager.Issuer));
                            claims.Add(new Claim(ClaimTypes.NameIdentifier, _user.UserID.ToString(), ClaimValueTypes.String, LoginManager.Issuer));
                            //获取权限
                            // string userMenus = GetUserMenu(_user.UserID).ToJson();
                            //claims.Add(new Claim(ClaimTypes.AuthorizationDecision, userMenus, ClaimValueTypes.String, LoginManager.Issuer));
                            claims.Add(new Claim(ClaimTypes.UserData, _user.ToJson(), ClaimValueTypes.String, LoginManager.Issuer));

                            //身份可以有多个身份 如:驾照/身份证/户口本
                            var userIdentity = new ClaimsIdentity(LoginManager.Issuer);
                            userIdentity.AddClaims(claims);

                            //主体,只有1个
                            var userPrincipal = new ClaimsPrincipal(userIdentity);

                            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal,
                                                          new AuthenticationProperties
                            {
                                ExpiresUtc   = DateTime.UtcNow.AddMinutes(remember == "on" ? (1440 * 30) : 1440),
                                IsPersistent = false,
                                AllowRefresh = false
                            });


                            re.Status     = true;
                            re.StatusCode = 0;
                            re.Message    = "登陆成功.";
                        }
                        else
                        {
                            re.Message = "该账户已禁用.";
                        }
                    }
                    else
                    {
                        re.Message = "用户名或密码错误.";
                    }
                }
                else
                {
                    re.Message = "用户名或密码不能为空";
                }
            }
            catch (Exception ex)
            {
                re.Message = ex.Message;
            }
            return(Ok(re));
            //return RedirectToLocal("/");
        }
Ejemplo n.º 5
0
        public async Task <bool> UpdateAsync(ESysUserInfo eSysUserInfo)
        {
            string sql = "update Sys_UserInfo set UserName=@UserName,RealName=@RealName,Pwd=@Pwd,Mobile=@Mobile,Wechat=@Wechat,OpenId=@OpenId,Dept=@Dept,Position=@Position,Status=@Status where UserID=@UserID;";

            return(await _context.ExecuteAsync(sql, eSysUserInfo) > 0);
        }
Ejemplo n.º 6
0
        public async Task <bool> AddAsync(ESysUserInfo eSysUserInfo)
        {
            string sql = "insert into Sys_UserInfo(UserName,RealName,Pwd,Mobile,Wechat,OpenId,Dept,Position,Status) values(@UserName,@RealName,@Pwd,@Mobile,@Wechat,@OpenId,@Dept,@Position,@Status);select @@Identity;";

            return(await _context.ExecuteAsync(sql, eSysUserInfo) > 0);
        }