Beispiel #1
0
        public ActionResult CreationSubmittion(AccountCreation m)
        {
            //check for blank entries
            if (m.Email == null || m.Password == null || m.confirmPassword == null || m.Fname == null || m.Lname == null || m.Phone_Num == null)
            {
                ViewBag.EmptyFields = "Must not leave any blank. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            //Check lengths
            if (m.Phone_Num.Length > 14)
            {
                ViewBag.InvalidPhone = "Phone number too long. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            if (m.Email.Length > 100)
            {
                ViewBag.InvalidEmail = "Email too long. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            if (m.Fname.Length > 100)
            {
                ViewBag.InvalidFname = "First name too long. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            if (m.Lname.Length > 100)
            {
                ViewBag.InvalidLname = "Last name too long. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            if (m.Password.Length > 100)
            {
                ViewBag.InvalidPassword = "******";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            //check for matching passwords
            if (!m.Password.Equals(m.confirmPassword))
            {
                ViewBag.InvalidPassword = "******";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            //Check for invalid email
            try
            {
                MailAddress mail = new MailAddress(m.Email);
            }
            catch (FormatException)
            {
                ViewBag.InvalidEmail = "This is not a valid email address. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            //Check for invalid phone_num - TODO need to fix to make areacode manditory
            Regex rg = new Regex(@"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$");

            if (!rg.IsMatch(m.Phone_Num))
            {
                ViewBag.InvalidPhone = "This is not a valid phone number. Try again.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            grabFromDB DB = new grabFromDB();


            //must check to see if user already exists
            if (DB.getUserListByEmail(m.Email).Count != 0)
            {
                ViewBag.InvalidEmail = "Email already used. Try a different one.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }

            if (DB.getUserListByPhone(m.Phone_Num).Count != 0)
            {
                ViewBag.InvalidPhone = "This phone number is already linked to an account. Please enter different one.";
                var universities = GetAllUniversities();
                m.Universities = GetSelectListItems(universities);
                return(View("AccountCreation", m));
            }


            DB.insertUser(m.Phone_Num, m.Email, m.University, m.Fname, m.Lname, m.Password);

            ViewBag.SuccessfullyCreated = "Your account was successfully created. Thanks for joining! Please sign in to continue.";

            LoginModel model = new LoginModel();

            return(View("LogIn", model));
        }
Beispiel #2
0
        public ActionResult ModifyUser(AdminUserResultModel m)
        {
            User          toModify       = Globals.getUserToModify();
            grabFromDB    DB             = new grabFromDB();
            List <string> modifiedReturn = new List <string>();

            if (m.Email != null && toModify.email != m.Email)
            {
                if (m.Email.Length > 100)
                {
                    ViewBag.InvalidEmail = "Email too long. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                if (DB.getUserListByEmail(m.Email).Count == 1)
                {
                    ViewBag.InvalidEmail = "This email is already associated with an account. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                //Check for invalid email
                try
                {
                    MailAddress mail = new MailAddress(m.Email);
                }
                catch (FormatException)
                {
                    ViewBag.InvalidEmail = "This is not a valid email address. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                DB.modifyUserEmail(m.Email, toModify.email);
                toModify.email = m.Email;
                modifiedReturn.Add("Email successfully changed.");
            }

            if (m.Password != null && toModify.pw != m.Password)
            {
                if (m.Password != m.confirmPassword)
                {
                    ViewBag.InvalidPassword = "******";
                    ViewBag.User            = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                if (m.Password.Length > 100 || m.confirmPassword.Length > 100)
                {
                    ViewBag.InvalidPassword = "******";
                    ViewBag.User            = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                DB.modifyUserPassword(m.Password, toModify.pw, toModify.email);
                modifiedReturn.Add("Password successfully changed");
            }

            if (m.Fname != null && toModify.fname != m.Fname)
            {
                if (m.Fname.Length > 100)
                {
                    ViewBag.InvalidFname = "First name too long. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                DB.modifyUserFname(m.Fname, toModify.fname, toModify.email);
                modifiedReturn.Add("First name successfully changed");
            }


            if (m.Lname != null && toModify.lname != m.Lname)
            {
                if (m.Lname.Length > 100)
                {
                    ViewBag.InvalidLname = "Last name too long. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                DB.modifyUserLname(m.Lname, toModify.lname, toModify.email);
                modifiedReturn.Add("Last name successfully changed.");
            }

            if (m.Phone_Num != null && toModify.phone != m.Phone_Num)
            {
                if (m.Phone_Num.Length > 14)
                {
                    ViewBag.InvalidPhone = "Phone number too long. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                Regex rg = new Regex(@"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$");
                if (!rg.IsMatch(m.Phone_Num))
                {
                    ViewBag.InvalidPhone = "This is not a valid phone number. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                if (DB.getUserListByPhone(m.Phone_Num).Count == 1)
                {
                    ViewBag.InvalidPhone = "Phone number already associated with an account. Try again.";
                    ViewBag.User         = toModify;
                    var universities = GetAllUniversities();
                    m.Universities = GetSelectListItems(universities);
                    return(View("UserEdit", m));
                }

                DB.modifyUserPhone(m.Phone_Num, toModify.phone, toModify.email);
                modifiedReturn.Add("Phone number successfully changed.");
            }

            if (m.University != null && m.University != toModify.Uni)
            {
                DB.modifyUserUniversity(m.University, toModify.Uni, toModify.email);
                modifiedReturn.Add("University successfully changed.");
            }



            ViewBag.ModifiedReturn = modifiedReturn;
            return(View("AdminPage"));
        }