Beispiel #1
0
        public ApiResponse <AuthResponse> RequestToken(AuthRequest req)
        {
            var user = _users.Find(req.Login, req.PasswordHash);

            if (user == null)
            {
                if (_users.Find(req.Login) == null)
                {
                    _logger.Debug(this, $"No user in repository with login '{req.Login}'");
                }
                else
                {
                    _logger.Debug(this, $"Invalid password for user with login '{req.Login}'");
                }
                return(new ClientError("Invalid login or password").AsError <AuthResponse>());
            }
            var token  = _token.CreateToken(user);
            var config = _config.Get();
            var state  = _states.FindOrCreate(user, s => _init.Init(s, config));

            state.Time.LastSyncTime = _time.RealTime;
            _states.Save(user, state.UpdateVersion());
            var response = new AuthResponse(token, state, config);

            _logger.Debug(this, $"User is logged in: '{user.Login}'");
            return(response.AsResult());
        }