Пример #1
0
        public IActionResult Auth([FromBody] UserSignInViewModel userSignInViewModel)
        {
            Models.Response.ResponseModel response = ResponseModelFactory.CreateInstance;
            DncUser user;

            user = _dbContext.DncUser.FirstOrDefault(x => x.LoginName == userSignInViewModel.UserName.Trim());

            string[] passwordSplit = user.Password.Split("$");

            if (user == null)
            {
                response.SetFailed("用户不存在");
                return(Ok(response));
            }

            if (passwordSplit[1] != PasswordCalculator.SaltPassword(passwordSplit[0], userSignInViewModel.PasswordMD5))
            {
                response.SetFailed("密码不正确");
                return(Ok(response));
            }

            try
            {
                response.SetData(TokenBulider(user));
                return(Ok(response));
            }
            catch (InvalidOperationException ex)
            {
                response.SetFailed(ex.Message);
                return(Ok(response));
            }
        }
Пример #2
0
        public IActionResult Profile()
        {
            Models.Response.ResponseModel response = ResponseModelFactory.CreateInstance;
            Guid    guid = AuthContextService.CurrentUser.Guid;
            DncUser user = _dbContext.DncUser.FirstOrDefaultAsync(x => x.Guid == guid).Result;

            response.SetData(new
            {
                access      = new string[] { },
                avator      = user.Avatar,
                userGuid    = user.Guid,
                userName    = user.DisplayName,
                userType    = user.UserType,
                permissions = GetPermissionsByGuid(guid)
            });
            return(Ok(response));
        }
Пример #3
0
        public IActionResult RefreshToken()
        {
            Guid currentUserGuid = Guid.Parse((from claim in HttpContext.User.Claims
                                               where claim.Type == "guid"
                                               select claim.Value).First());

            Models.Response.ResponseModel response = ResponseModelFactory.CreateInstance;
            DncUser user = _dbContext.DncUser.FirstOrDefault(x => x.Guid == currentUserGuid);

            try
            {
                response.SetData(TokenBulider(user));
                return(Ok(response));
            }
            catch (InvalidOperationException ex)
            {
                response.SetFailed(ex.Message);
                return(Ok(response));
            }
        }
Пример #4
0
 public IActionResult Permission(Guid guid)
 {
     Models.Response.ResponseModel response = ResponseModelFactory.CreateInstance;
     response.SetData(GetPermissionsByGuid(guid));
     return(Ok(response));
 }