Beispiel #1
0
        public ActionResult ChangePassword(Login model)
        {
            if (ModelState.IsValid)
            {

                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {

                    var temp = from p in db.Logins
                               where p.Password.Equals(model.Password)
                               select p.Password;

                    if (temp.Equals(null))
                    {
                        changePasswordSucceeded = false;
                    }
                    else
                    {
                        changePasswordSucceeded = true;
                        db.Logins.Attach(model);
                        db.ObjectStateManager.ChangeObjectState(model, System.Data.EntityState.Modified);
                        db.SaveChanges();

                    }
                  //  MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
                  //  changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Logins EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLogins(Login login)
 {
     base.AddObject("Logins", login);
 }
Beispiel #3
0
        public ActionResult LogOn(Login model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var namepass = from p in db.Logins
                               where p.UserName.Equals(returnUrl[0]) //& p.Password.Equals(returnUrl[1])
                               select p.ParentID;

                //// Grab the row that matches the password we need.
                //Login product = (from p in db.Logins
                //                   where p.UserName.Equals(returnUrl[0])
                //                   select p).Single();

                Login product = db.Logins.Single(p => p.UserName.Equals(model.UserName));

                //var tempId = from p in db.Parents
                //             where p.First_Name.Equals(model.UserName)
                //             select p;

                // Now compare the passward entered to the passward in the row returned.
                if (product.Password.Equals(model.Password))
                {

                    int x= (int)product.ParentID;
                    FormsAuthentication.SetAuthCookie(product.UserName, true);
                    return RedirectToAction("AfterLog", "Home", new {id = x}) ;
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }

                //if (Membership.ValidateUser(model.UserName, model.Password))
                //{
                //   // FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                //    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                //        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                //    {
                //        return Redirect(returnUrl);
                //    }
                //    else
                //    {
                //        var students = from p in db.Logins
                //                       where p.ParentID == model.ParentID
                //                       select p;

                //        return RedirectToAction("Index", "Home");
                //    }
                //}
                //else
                //{
                //    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                //}
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #4
0
 /// <summary>
 /// Create a new Login object.
 /// </summary>
 /// <param name="userName">Initial value of the UserName property.</param>
 public static Login CreateLogin(global::System.String userName)
 {
     Login login = new Login();
     login.UserName = userName;
     return login;
 }