Ejemplo n.º 1
0
 public IActionResult ChangePwd([FromBody] PwdDto pwdDto)
 {
     try
     {
         var           sysUserinfo   = _context.SysUsers.Where(x => x.SysUserId == pwdDto.SysUserId).FirstOrDefault();
         PwdTransition pwdTransition = new PwdTransition();
         var           oldpwd        = pwdTransition.ToHash(pwdDto.Pwd, sysUserinfo.Salt);
         if (oldpwd != sysUserinfo.Pwd)
         {
             return(BadRequest("原密码错误!请重新输入"));
         }
         if (pwdDto.NewPwd != pwdDto.SurePwd)
         {
             return(BadRequest("二次密码输入不一致!请重新输入"));
         }
         string salt   = Guid.NewGuid().ToString();
         var    newpwd = pwdTransition.ToHash(pwdDto.NewPwd, salt);
         sysUserinfo.Salt = salt;
         sysUserinfo.Pwd  = newpwd;
         _context.SaveChanges();
         return(Ok("修改密码成功!请重新登陆"));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Ejemplo n.º 2
0
 public IActionResult AppLogin([FromBody] SysUserDto sysUserDto)
 {
     try
     {
         var sysuserinfo = _context.SysUsers.Where(x => x.Account == sysUserDto.Account).FirstOrDefault();
         if (sysuserinfo == null)
         {
             return(BadRequest("不存在此账号!"));
         }
         PwdTransition pwdTransition = new PwdTransition();
         var           Hashpwd       = pwdTransition.ToHash(sysUserDto.Pwd, sysuserinfo.Salt);
         if (sysuserinfo.Pwd != Hashpwd)
         {
             return(BadRequest("密码不正确!请重新输入"));
         }
         var token = Guid.NewGuid().ToString();
         sysuserinfo.Token = token;
         sysuserinfo.Ip    = HttpContext.Connection.RemoteIpAddress.ToString();
         _context.SaveChanges();
         return(Ok(sysuserinfo));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Ejemplo n.º 3
0
 public IActionResult Login([FromBody] SysUserDto sysUserDto)
 {
     try
     {
         var sysuserinfo = _context.SysUsers.Where(x => x.Account == sysUserDto.Account).FirstOrDefault();
         if (sysuserinfo == null)
         {
             return(BadRequest("不存在此账号!"));
         }
         PwdTransition pwdTransition = new PwdTransition();
         var           Hashpwd       = pwdTransition.ToHash(sysUserDto.Pwd, sysuserinfo.Salt);
         if (sysuserinfo.Pwd != Hashpwd)
         {
             return(BadRequest("密码不正确!请重新输入"));
         }
         string validateNum = HttpContext.Session.GetString("Code_ValidateNum");
         HttpContext.Session.Remove("Code_ValidateNum");
         if (validateNum != sysUserDto.Code.ToUpper())
         {
             return(BadRequest("输入验证码有误!"));
         }
         var token = Guid.NewGuid().ToString();
         sysuserinfo.Token = token;
         sysuserinfo.Ip    = HttpContext.Connection.RemoteIpAddress.ToString();
         _context.SaveChanges();
         var loginInfo = sysuserinfo.SysUserId + "&" + token;
         return(Ok(loginInfo));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 异步建立数据值
        /// </summary>
        /// <returns></returns>
        private async Task SeedDate()
        {
            if (!_context.SysUsers.Any())
            {
                PwdTransition pwdTransition = new PwdTransition();
                var           Salt          = Guid.NewGuid().ToString();
                var           Hashpwd       = pwdTransition.ToHash("123aaa", Salt);
                var           sysuser       = new SysUser {
                    Account = "admin", Pwd = Hashpwd, Salt = Salt, Name = "超管", CreatDate = DateTime.Now
                };
                await _context.SysUsers.AddAsync(sysuser);

                _context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 public IActionResult InitPwd(long id)
 {
     try
     {
         var           sysUserinfo   = _context.SysUsers.Where(x => x.SysUserId == id).FirstOrDefault();
         PwdTransition pwdTransition = new PwdTransition();
         var           Salt          = Guid.NewGuid().ToString();
         var           Hashpwd       = pwdTransition.ToHash("123aaa", Salt);
         sysUserinfo.Pwd  = Hashpwd;
         sysUserinfo.Salt = Salt;
         _context.SaveChanges();
         return(Ok("初始化密码成功"));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Ejemplo n.º 6
0
        public IActionResult AddSysUser([FromBody] SysUserDto sysUserDto)
        {
            try
            {
                PwdTransition pwdTransition = new PwdTransition();
                var           Salt          = Guid.NewGuid().ToString();
                var           Hashpwd       = pwdTransition.ToHash("123aaa", Salt);
                string        ip            = HttpContext.Connection.RemoteIpAddress.ToString();

                var SysUserInfo = new SysUser()
                {
                    Account     = sysUserDto.Account,
                    Pwd         = Hashpwd,
                    Salt        = Salt,
                    Addr        = sysUserDto.Addr,
                    Comments    = sysUserDto.Comments,
                    CreatDate   = DateTime.Now,
                    Ip          = ip,
                    Name        = sysUserDto.Name,
                    Phone       = sysUserDto.Phone,
                    Latitude    = sysUserDto.Latitude,
                    Longitude   = sysUserDto.Longitude,
                    Popenid     = sysUserDto.Popenid,
                    Comment1    = sysUserDto.Comment1,
                    Price       = sysUserDto.Price,
                    TemIdAccept = sysUserDto.TemIdAccept,
                    TemIdRefuse = sysUserDto.TemIdRefuse,
                    TemIdOrder  = sysUserDto.TemIdOrder,
                    TemIdSend   = sysUserDto.TemIdSend,
                    IsOpen      = sysUserDto.IsOpen
                };
                _context.SysUsers.Add(SysUserInfo);
                _context.SaveChanges();
                return(Ok("添加成功"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }