Esempio n. 1
0
        private object ValidateLogin(LoginRequest loginRequest)
        {
            var login        = _securityService.LoginByNameOrDefault(loginRequest.Email);
            var unauthorized = new RequestEvent <LoginRequest>(Context, RequestName.UnauthorizedLogin, loginRequest);

            if (login == null)
            {
                _publisher.Publish(unauthorized);
                return(HttpStatusCode.Unauthorized);
            }
            ;

            var loginToken = _securityService.LoginTokenOrDefault(login, loginRequest.Password);
            var user       = _mapper.UserRecordToUser(login?.User);

            if (loginToken == null)
            {
                _publisher.Publish(unauthorized);
                return(HttpStatusCode.Unauthorized);
            }
            ;
            var encodedToken = _securityService.EncodeToken(loginToken);

            return(Negotiate
                   .WithModel(new { encodedToken, user })
                   .WithStatusCode(HttpStatusCode.OK));
        }