Ejemplo n.º 1
0
        public ActionResult Create(User userModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (userModel.password == userModel.conformPassword)
                    {
                        var db = new DatabaseDataContext();
                        var user=db.Users.FirstOrDefault(u=>u.email==userModel.email);
                        if (user == null)
                        {
                            user = new User();
                            user.name = userModel.name;
                            user.email = userModel.email;
                            user.password = userModel.password;

                            db.Users.InsertOnSubmit(user);
                            db.SubmitChanges();
                            return RedirectToAction("LogOn");

                        }else ModelState.AddModelError("", "User with this email already exist");
                    }else ModelState.AddModelError("","Passwords must be match");
                }
                return View(userModel);
            }
            catch
            {
                return View(userModel);
            }
        }
Ejemplo n.º 2
0
        public ActionResult ReminderPassword(User userModel)
        {
            ModelState.Remove("name");
            ModelState.Remove("conformPassword");
            ModelState.Remove("password");

            if (ModelState.IsValid)
            {
                var db = new DatabaseDataContext();
                var user = db.Users.FirstOrDefault(u => u.email == userModel.email);

                if (user != null)
                {
                    System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
                    Message.Subject = "Reminder password";
                    Message.Body = "Hello "+user.name+ "! Your password for ToDo : \n"+user.password;
                    Message.BodyEncoding = System.Text.Encoding.ASCII;
                    Message.From=new MailAddress("*****@*****.**");
                    Message.To.Add(new MailAddress(user.email));
                    System.Net.Mail.SmtpClient Smtp = new SmtpClient("smtp.mail.ru");
                    Smtp.EnableSsl = true;
                    Smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "fktnerg3z7");
                    Smtp.Send(Message);

                    return RedirectToAction("LogOn");
                }
                else
                {
                    ModelState.AddModelError("", "This email does not exist");
                }
            }

            return View(userModel);
        }
Ejemplo n.º 3
0
        public ActionResult LogOn(User userModel)
        {
            ModelState.Remove("name");
            ModelState.Remove("conformPassword");
            ModelState.Remove("password");

            if (ModelState.IsValid)
            {
                var db = new DatabaseDataContext();
                var user = db.Users.FirstOrDefault(u=>u.email==userModel.email);

                if (user!=null && user.password==userModel.password)
                {
                    FormsAuthentication.RedirectFromLoginPage(user.name, userModel.remember);
                    return RedirectToAction("Index", "Task", new {id= user.user_id,done=false});
                }
                else
                {
                    ModelState.AddModelError("", "Login and/or password are incorrect");
                }
            }

            return View(userModel);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int id, User userModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add update logic here
                    var db = new DatabaseDataContext();
                    var user = db.Users.SingleOrDefault(u => u.user_id == id);

                    user.name = userModel.name;
                    user.email = userModel.email;
                    user.password = userModel.password;

                    db.SubmitChanges();
                    return RedirectToAction("Index");
                }

                return View(userModel);
            }
            catch
            {
                return View(userModel);
            }
        }
Ejemplo n.º 5
0
 partial void DeleteUser(User instance);
Ejemplo n.º 6
0
 partial void UpdateUser(User instance);
Ejemplo n.º 7
0
 partial void InsertUser(User instance);