public Eventual.Model.LoginCredentials LoginCredentials()
 {
     Eventual.Model.LoginCredentials login = new Eventual.Model.LoginCredentials();
     login.UserEmail    = "*****@*****.**";
     login.UserPassword = "******";
     return(login);
 }
        public HttpResponseMessage Login(Eventual.Model.LoginCredentials login)
        {
            if (string.IsNullOrEmpty(login.UserEmail) || string.IsNullOrEmpty(login.UserPassword))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid username or password"));
            }

            User user = db.Users.FirstOrDefault(u => u.UserEmail.Equals(login.UserEmail));

            if (user == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid username or password"));
            }

            if (!ArePasswordsEqual(user.UserHashedPassword, login.UserPassword))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            db.Entry(user).State = System.Data.Entity.EntityState.Detached;

            //Dictionary<string, object> headers = new Dictionary<string, object>();
            //todo to convert unix time to timestamp string and then expiration two hours from now
            //Dictionary<string, object> claims = new Dictionary<string, object>
            //{
            //    {"iss", "API.Eventual"},
            //    {"iat", ""},
            //    {"exp", ""},
            //    {"userID", user.UserID.ToString() },
            //    { "userEmail", user.UserEmail }
            //};

            //string secret = "fuckthisshit";
            //string jwt = new JsonWebToken(secret).GenerateToken(claims, headers);

            //returns validated user
            return(Request.CreateResponse(HttpStatusCode.OK, user));
        }
 public void TestLogin()
 {
     Eventual.Model.LoginCredentials login = LoginCredentials();
     Assert.AreEqual(login.UserEmail, "*****@*****.**");
     Assert.AreEqual(login.UserPassword, "loginpassword");
 }
Example #4
0
        public static Eventual.Model.User LoginValidator(Controllers.LoginController login, Eventual.Model.LoginCredentials loginCredential)
        {
            HttpResponseMessage response = login.Login(loginCredential);

            if (response.IsSuccessStatusCode)
            {
                var user = response.Content.ReadAsAsync <Eventual.Model.User>().Result;

                return(user);
            }

            return(null);
        }