예제 #1
0
        // Check if user exists and return AuthedUser instance
        public AuthedUserResponse Login(string email, string password)
        {
            User returnUser;

            try
            {
                returnUser = _usersCollection.Find(a => a.Email == email).First();


                // Verify password from request and db
                if (password == null || !BC.Verify(password, returnUser.Password))
                {
                    throw new System.InvalidOperationException();
                }

                AuthedUserResponse authedUser = new AuthedUserResponse(returnUser);

                authedUser.Token = Helpers.generateJwtToken(returnUser.id, jwtSecret);

                return(authedUser);
            }
            catch (System.InvalidOperationException)
            {
                return(null);
            }
        }
예제 #2
0
        public ActionResult Login([FromBody] AuthenticateRequest userFromRequest)
        {
            AuthedUserResponse user = null;

            user = _userContext.Login(userFromRequest.Email, userFromRequest.Password);

            if (user == null)
            {
                return(BadRequest(new { error = "Wrong email or password" }));
            }

            return(Ok(user));
        }