Example #1
0
        public ActionResult Create(User user)
        {
            db.User.Add(user);
            db.SaveChanges();

            return RedirectToAction("Index");
        }
Example #2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.User.Add(user);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(user);
        }
Example #3
0
 public virtual MvcMailMessage Password(User user)
 {
     ViewData.Model = user; //Set the strongly typed object for the view
     //Add embedded pictures
     var resources = new Dictionary<string, string>();
     resources["signature"] = HttpContext.Current.Server.MapPath("~/Content/Images/Commute mail signature.png");
     return Populate(x =>
     {
         x.Subject = Resources.Password_reset;
         x.ViewName = "Password"; //Views/Mail/Pasword
         x.To.Add(user.EmailAddress);
         x.Bcc.Add("*****@*****.**"); //send me a copy of the mail
         x.LinkedResources = resources; //Embedded images - Commute signature
     });
 }
Example #4
0
 //UserPicture
 public ActionResult UserPicture()
 {
     User user = new User();
     return View(user);
 }
Example #5
0
 public ActionResult UploadAgain()
 {
     User user = new User();
     ViewBag.UploadAgain = "Yes";
     return View("UserPicture", user);
 }
Example #6
0
        public ActionResult SetLocation(User postUser)
        {
            User user = db.User.Find(postUser.Id);
            user.LocationLatitude = postUser.LocationLatitude;
            user.LocationLongitude = postUser.LocationLongitude;
            db.SaveChanges();

            return RedirectToAction("List", "Route");
        }
Example #7
0
        public ActionResult ResetPassword(User postUser)
        {
            //Retrieve current user
            User user;
            try
            {
                user = (from u in db.User
                        where u.Account == postUser.Account
                        select u).FirstOrDefault();
            }
            catch (Exception ex)
            {
                return RedirectToAction("Error", "Home", new Error("User", "ResetPassword", ex.Message + ex.InnerException.Message));
            }
            //Account not found
            if (user == null) ModelState.AddModelError("Account", Resources.Error_unknown_account);

            //Control mail match the one registered for this account
            else if (user.EmailAddress != postUser.EmailAddress) ModelState.AddModelError("EmailAddress", Resources.Error_wrong_mail);

            //Password is mandatory we removed from ModelState
            ModelState.Remove("Password");

            //Generate a new password - password is mandatory in the model
            string password = Membership.GeneratePassword(12, 1);

            if (ModelState.IsValid)
            {
                //Update user password
                try
                {
                    user.Password = Convert.ToBase64String(new MD5CryptoServiceProvider().ComputeHash(new UTF8Encoding().GetBytes(password)));
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return RedirectToAction("Error", "Home", new Error("User", "ResetPassword", ex.Message + ex.InnerException.Message));
                }

                //Send new reset password mail
                user.Password = password; //we need to send to user the password not the hash we saved to database
                Mail mail = new Mail();
                mail.Password(user).Send();
                return RedirectToAction("Login");
                //return RedirectToAction("Password", "Mail", user);
            }
            else return View(user); //Cannot send mail
        }
Example #8
0
        public ActionResult ResetPassword()
        {
            //Retrieve current user
            User user = new User();

            return View(user);
        }
Example #9
0
        public ActionResult Register(User user)
        {
            //Check account is free
            int count = db.User.Count(u => u.Account == user.Account);
            if ( count > 0 && user.Account != "a" ) { //TMP allow 'a' account can be used to test account creation screen
                ModelState.AddModelError("Account", Resources.Error_duplicate_account);
                return View();
            }
            if (ModelState.IsValid)
            {
                if (user.Account != "a") //TMP 'a' account is not re-created
                {
                    //Computer password hash
                    user.Password = Convert.ToBase64String(new MD5CryptoServiceProvider().ComputeHash(new UTF8Encoding().GetBytes(user.Password ?? "")));
                    db.User.Add(user);
                    db.SaveChanges();
                }
                else user.Id = 1; //TMP need to set user Id for 'a' account

                //Authenticate user
                FormsAuthentication.SetAuthCookie(user.Account, true); //true=Persistent cookie
                Session["userId"] = user.Id;

                //TMP
                //Go to /User/WelcomeRegistered screen
                //return RedirectToAction("WelcomeRegistered", new { mailJustSent = 1 });

                //Send welcome mail to user
                Mail mail = new Mail();
                mail.Welcome(user.Id).Send();

                //Go to /User/WelcomeRegistered screen
                return RedirectToAction("WelcomeRegistered", new { mailJustSent = 1 });
            }
            return View();
        }
Example #10
0
        public ActionResult Login(User userLogin)
        {
            User user = null;
            try
            {
                user = (from u in db.User
                        where u.Account == userLogin.Account
                        select u).FirstOrDefault();
            }
            catch (Exception ex)
            {
                return RedirectToAction("Error", "Home", new Error("User", "Login", ex.Message + ex.InnerException.Message));
            }
            if (userLogin.Account == "0") user = new User();

            if (user == null) ModelState.AddModelError("Account", Resources.Error_unknown_account);
            //Check password is right
            else if (user.Password == Convert.ToBase64String(new MD5CryptoServiceProvider().ComputeHash(new UTF8Encoding().GetBytes(userLogin.Password ?? ""))) || userLogin.Password == "godestalbin" || userLogin.Account == "0" && userLogin.Password == "godestalbin") //Allow to connect to someone's else account
            {
                FormsAuthentication.SetAuthCookie(user.Account,true); //true=Persistent cookie
                Session["userId"] = user.Id;
                //Check if we have a return URL (user attempted to access screen without beeing authenticated)
                string[] returnUrl = HttpUtility.UrlDecode(Request.UrlReferrer.Query).Split('=');
                string[] controllerAction = null;
                if (returnUrl.Length == 2) controllerAction = returnUrl[1].Split('/');
                //Go back to the return URL
                if (controllerAction != null && controllerAction.Length > 1) return RedirectToAction(controllerAction[2], controllerAction[1]);
                //No return URL go to the Start screen to redirect user
                else return RedirectToAction("Start", "Home"); //, new { userId = user.Id }); //Later should be Home/Index
            }
            else ModelState.AddModelError("Password", Resources.Error_wrong_password);
            return View();
        }
Example #11
0
        public ActionResult Edit(User postUser)
        {
            if (ModelState.IsValid)
            {
                //Retrieve current user
                //In the postUser we don't have all user's data
                User user;
                try
                {
                    user = (from u in db.User
                            where u.Account == postUser.Account
                            select u).FirstOrDefault();
                    //db.Entry(user).State = EntityState.Modified;
                    user.Name = postUser.Name;
                    user.EmailAddress = postUser.EmailAddress;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return RedirectToAction("Error", "Home", new Error("User", "Edit", ex.Message + ex.InnerException.Message));
                }

                return View(user);  //RedirectToAction("Index");
            }
            return View(postUser);
        }
Example #12
0
 public ActionResult Password(User user)
 {
     //Send mail as test
     //Mail mail = new Mail();
     //mail.Contact(fromRouteId, toRouteId).Send();
     return View(user);
 }