Пример #1
0
        public object FindByLogin(WebUserVO WebUser)
        {
            bool credentialsIsValid = false;

            if (WebUser != null && !string.IsNullOrWhiteSpace(WebUser.Login))
            {
                var baseWebUser = _repository.FindByLogin(WebUser.Login);
                credentialsIsValid = (baseWebUser != null && WebUser.Login == baseWebUser.Login && WebUser.AccessKey == baseWebUser.AccessKey);
            }
            if (credentialsIsValid)
            {
                ClaimsIdentity identity = new ClaimsIdentity(
                    new GenericIdentity(WebUser.Login, "Login"),
                    new[]
                {
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")),
                    new Claim(JwtRegisteredClaimNames.UniqueName, WebUser.Login)
                }
                    );

                DateTime createDate     = DateTime.Now;
                DateTime expirationDate = createDate + TimeSpan.FromSeconds(_tokenConfigurations.Seconds);

                var    handler = new JwtSecurityTokenHandler();
                string token   = CreateToken(identity, createDate, expirationDate, handler);

                return(SuccessObject(createDate, expirationDate, token));
            }
            else
            {
                return(ExceptionObject());
            }
        }
 public object Post([FromBody] WebUserVO user)
 {
     if (user == null)
     {
         return(BadRequest());
     }
     return(_loginBusiness.FindByLogin(user));
 }