Esempio n. 1
0
        public void UpdatePassword(string oldPassword, string newPassword, string confirmNewPassword)
        {
            if (newPassword != confirmNewPassword)
            {
                throw new Exceptions.InvalidDataException("New password and confirm new password do not match.");
            }

            var login = new Majorsilence.Vpn.Logic.Login(details.Email, oldPassword);

            login.Execute();

            if (!login.LoggedIn)
            {
                throw new Exceptions.InvalidDataException("Invalid old password");
            }


            var pwd = new CreatePasswords(newPassword, details.FirstName + details.LastName);

            using (var cn = Majorsilence.Vpn.Logic.InitializeSettings.DbFactory)
            {
                cn.Open();

                details.Password = pwd.Password;
                details.Salt     = pwd.Salt;

                cn.Update(details);
            }
        }
Esempio n. 2
0
        public void InvalidUsernameAndPasswordLogin()
        {
            var login = new Majorsilence.Vpn.Logic.Login("hi there", "wrong password");

            login.Execute();

            Assert.That(login.LoggedIn, Is.False);
            Assert.That(login.IsAdmin, Is.False);
            Assert.That(login.Username, Is.EqualTo("hi there"));
            Assert.That(login.UserId, Is.EqualTo(-1));
        }
Esempio n. 3
0
        public void InvalidPasswordLogin()
        {
            var login = new Majorsilence.Vpn.Logic.Login(this.emailAddress, "wrong password");

            login.Execute();

            Assert.That(login.LoggedIn, Is.False);
            Assert.That(login.IsAdmin, Is.False);
            Assert.That(login.Username, Is.EqualTo(this.emailAddress));
            Assert.That(login.UserId, Is.EqualTo(-1));
        }
Esempio n. 4
0
        public void CanLogin()
        {
            var login = new Majorsilence.Vpn.Logic.Login(emailAddress, this.password);

            login.Execute();

            System.Console.WriteLine(login.LoggedIn);
            Assert.That(login.LoggedIn, Is.True);

            System.Console.WriteLine(login.IsAdmin);
            Assert.That(login.IsAdmin, Is.True);

            System.Console.WriteLine(login.Username);
            Assert.That(login.Username, Is.EqualTo(emailAddress));

            System.Console.WriteLine(login.UserId);
            Assert.That(login.UserId, Is.EqualTo(this.userid));
        }
Esempio n. 5
0
        public void LoginValidation(string username, string password)
        {
            var login = new Majorsilence.Vpn.Logic.Login(username, password);

            try
            {
                login.Execute();
            }
            catch (Majorsilence.Vpn.Logic.Exceptions.InvalidDataException)
            {
                this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return;
            }

            sessionInstance.LoggedIn = login.LoggedIn;
            sessionInstance.Username = username;
            sessionInstance.UserId   = login.UserId;
            sessionInstance.IsAdmin  = login.IsAdmin;

            if (sessionInstance.LoggedIn)
            {
                // if payments have expired or were never setup prompt the user
                // to setup payments
                var paymets = new Majorsilence.Vpn.Logic.Payments.Payment(sessionInstance.UserId);
                if (paymets.IsExpired())
                {
                    this.HttpContext.Response.StatusCode = 250;
                }
                else
                {
                    this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                }
            }
            else
            {
                this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
            }
        }
Esempio n. 6
0
        public ContentResult Auth()
        {
            // Majorsilence.Vpn.Logic.DTO.ApiAuthResponse results;

            try
            {
                if (!HttpContext.Request.Headers.Keys.Contains("Authorization", StringComparer.OrdinalIgnoreCase))
                {
                    HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
                    return(Content("Authorization not sent"));
                }

                string authHeader = HttpContext.Request.Headers["Authorization"];
                var    creds      = ParseAuthHeader(authHeader);


                var login = new Majorsilence.Vpn.Logic.Login(creds[0], creds[1]);


                try
                {
                    login.Execute();
                }
                catch (Majorsilence.Vpn.Logic.Exceptions.InvalidDataException ex)
                {
                    HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                    Majorsilence.Vpn.Logic.Helpers.Logging.Log(ex);
                    return(Content("InternalServerError"));
                }


                if (!login.LoggedIn)
                {
                    HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
                    return(Content("Unauthorized"));
                }
                sessionVars.LoggedIn = login.LoggedIn;
                sessionVars.IsAdmin  = login.IsAdmin;
                sessionVars.UserId   = login.UserId;
                sessionVars.Username = login.Username;



                var toks    = new Majorsilence.Vpn.Logic.Accounts.UserApiTokens();
                var tokData = toks.Retrieve(login.UserId);

                var results = new Majorsilence.Vpn.Logic.DTO.ApiAuthResponse()
                {
                    Token1          = tokData.Token1,
                    Token2          = tokData.Token2,
                    Token1ExpireUtc = tokData.Token1ExpireTime,
                    Token2ExpireUtc = tokData.Token2ExpireTime,
                    UserId          = sessionVars.UserId
                };

                var json = Newtonsoft.Json.JsonConvert.SerializeObject(results);

                HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                return(Content(json));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                Majorsilence.Vpn.Logic.Helpers.Logging.Log(ex);
                return(Content("InternalServerError"));
            }
        }