Example #1
0
        public void TestLogIn()
        {
            string user1Name            = "";
            User   user2                = null;
            User   user3                = null;
            User   user4                = null;
            bool   noExceptionWasThrown = true;

            try
            {
                UserProcessor up = new UserProcessor();
                up.InsertNewUser("name", "*****@*****.**", "password");
                up.InsertNewUser("other name", "*****@*****.**", "password");

                User user1 = up.LogInUser("name", "password");
                user2     = up.LogInUser("other name", "password");
                user3     = up.LogInUser("name", "wrong password");
                user4     = up.LogInUser("name", "Password");
                user1Name = user1.UserName;
            }catch (Exception)
            {
                noExceptionWasThrown = false;
            }finally
            {
                //CleanUp
                UserAccess userAccess = new UserAccess();
                userAccess.DeleteByName("name");
                userAccess.DeleteByName("other name");
            }
            Assert.AreEqual("name", user1Name);
            Assert.IsNull(user2);
            Assert.IsNull(user3);
            Assert.IsNull(user4);
            Assert.IsTrue(noExceptionWasThrown);
        }
Example #2
0
        public void TestInsertApiKey()
        {
            bool   test1 = false;
            bool   test2 = true;
            bool   noExceptionWasThrown = true;
            string apikey = "";

            try
            {
                UserProcessor up = new UserProcessor();
                up.InsertNewUser("name", "*****@*****.**", "password");

                test1 = up.InsertApiKey("*****@*****.**", "key");
                test2 = up.InsertApiKey("Non existing email address", "key");
                User user = up.LogInUser("*****@*****.**", "password");
                apikey = user.ApiKey;
            }catch (Exception)
            {
                noExceptionWasThrown = false;
            }finally
            {
                //CleanUp
                UserAccess userAccess = new UserAccess();
                userAccess.DeleteByName("name");
            }
            Assert.IsTrue(test1);
            Assert.IsFalse(test2);
            Assert.AreEqual("key", apikey);
            Assert.IsTrue(noExceptionWasThrown);
        }
Example #3
0
        public ActionResult <string> LogIn([FromBody] User user)
        {
            User tempUser = userProcessor.LogInUser(user.UserName, user.Password);

            if (tempUser != null)
            {
                IAuthContainerModel model       = GetJWTContainerModel(tempUser.UserName, tempUser.EmailAddress, tempUser.UserRole);
                IAuthService        authService = new JWTService(clientSettings.Value.SecretKey);
                return(authService.GenerateToken(model));
            }
            return(BadRequest("Invalid login information was given"));
        }