コード例 #1
0
        public void Test_CheckLoginCredentials_BadPassword()
        {
            DBAccessor    dba      = new DBAccessor();
            LogonResponse response = dba.CheckLoginCredentials(TestConstants.CHECKLOGINCREDENTIALS_VALIDEMAIL, TestConstants.CHECKLOGINCREDENTIALS_INVALIDPASS);

            Assert.AreEqual((int)LogonResults.PASSWORDMISMATCH, response.success);
        }
コード例 #2
0
        public void Test_CheckLoginCredentials_BadUsername()
        {
            DBAccessor    dba      = new DBAccessor();
            LogonResponse response = dba.CheckLoginCredentials(TestConstants.CHECKLOGINCREDENTIALS_INVALIDEMAIL, "Don't Care");

            Assert.AreEqual((int)LogonResults.USERNOTFOUND, response.success);
        }
コード例 #3
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                String        email  = User.Identity.Name;
                DBAccessor    dba    = new DBAccessor();
                LogonResponse result = dba.CheckLoginCredentials(email, model.OldPassword);

                if (result.success == (int)LogonResults.SUCCESS)
                {
                    if (dba.UpdateUserPassword(email, model.NewPassword))
                    {
                        return(RedirectToAction("ChangePasswordSuccess"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Password update failed, try again.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", result.errorMessage);
                }
            }
            return(View(model));
        }
コード例 #4
0
        public ActionResult Edit(EditModel model)
        {
            if (ModelState.IsValid)
            {
                // Update the user in the MySQL DB
                String        oldEmail = User.Identity.Name;
                DBAccessor    dba      = new DBAccessor();
                LogonResponse result   = dba.CheckLoginCredentials(oldEmail, model.Password);

                if (result.success == (int)LogonResults.SUCCESS)
                {
                    Person updateUser = new Person(model.FirstName, model.LastName, model.Email, model.ImageURL, "", model.Birthday, model.Height, model.Weight);
                    dba.UpdateUserInformation(oldEmail, updateUser);

                    // Set the appropriate cookies
                    FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);
                    HttpCookie cookie = new HttpCookie(AppConstants.COOKIE_NAME, model.FirstName + " " + model.LastName);
                    cookie.Expires = DateTime.Now.AddDays(1000);
                    this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
                }
                else
                {
                    ModelState.AddModelError("", result.errorMessage);
                }
            }

            return(View(model));
        }
コード例 #5
0
        public void Test_CheckLoginCredentials_Valid()
        {
            DBAccessor    dba      = new DBAccessor();
            LogonResponse response = dba.CheckLoginCredentials(TestConstants.CHECKLOGINCREDENTIALS_VALIDEMAIL, TestConstants.CHECKLOGINCREDENTIALS_VALIDPASS);

            Assert.AreEqual((int)LogonResults.SUCCESS, response.success);
            Assert.AreEqual(TestConstants.CHECKLOGINCREDENTIALS_VALIDEMAIL, response.user.email);
            Assert.AreEqual(TestConstants.CHECKLOGINCREDENTIALS_FIRSTNAME, response.user.firstName);
            Assert.AreEqual(TestConstants.CHECKLOGINCREDENTIALS_LASTNAME, response.user.lastName);
        }
コード例 #6
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                // This should be a DB check instead of Membership.ValidateUser
                DBAccessor    dba    = new DBAccessor();
                LogonResponse result = dba.CheckLoginCredentials(model.Email, model.Password);

                if (result.success == (int)LogonResults.SUCCESS)
                {
                    Person user = dba.GetPersonInformation(model.Email);
                    FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);

                    // Add a name cookie
                    HttpCookie cookie = new HttpCookie(AppConstants.COOKIE_NAME, result.user.firstName + " " + result.user.lastName);
                    cookie.Expires = DateTime.Now.AddDays(1000);
                    this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);

                    // Add a coach permission cookie
                    string permission = "false";
                    if (user.permissions.coachEnabled)
                    {
                        permission = "true";
                    }
                    cookie         = new HttpCookie(AppConstants.COOKIE_COACH_PERMISSION, permission);
                    cookie.Expires = DateTime.Now.AddDays(1000);
                    this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", result.errorMessage);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }