public ActionResult AddUser(Users user)
        {
            Logon logIn = null;

            if (!user.Password_Field.Equals(user.Password_Field1))
            {
                ModelState.AddModelError("Password_Field", "The passwords entered do not match");
                return(View("SignUp", user));
            }
            else
            {
                using (MySqlConnection conn = DBUtils.GetConnection())
                {
                    UsersRepository repo  = new UsersRepository(conn);
                    Users           isNew = repo.GetByName(user.UserName);
                    if (isNew != null)
                    {
                        ModelState.AddModelError("UserName", "This User Name Already Exists");
                        return(View("SignUp", user));
                    }
                    else
                    {
                        if (ModelState.IsValid)
                        {
                            Dictionary <String, Object> hash = new Dictionary <String, Object>();
                            hash.Add("UserName", user.UserName);
                            hash.Add("Password", user.Password_Field);
                            hash.Add("FirstName", user.FirstName);
                            hash.Add("LastName", user.LastName);
                            hash.Add("PhoneNumber", user.PhoneNumber);
                            hash.Add("Street", user.Street);
                            hash.Add("City", user.City);
                            hash.Add("ZipCode", user.ZipCode);
                            hash.Add("Email", user.Email);
                            repo.SetAll(hash);
                            LogonRepository repo1 = new LogonRepository(conn);
                            logIn = repo1.GetByName(user.UserName);
                        }
                    }
                    if (logIn != null)
                    {
                        return(View("Login", logIn));
                    }
                    else
                    {
                        return(View("SignUp"));
                    }
                }
            }
            return(RedirectToAction("Error"));
        }
Beispiel #2
0
        public HttpResponseMessage Post(Logon logon)
        {
            Logon users = null;

            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                LogonRepository repo = new LogonRepository(conn);
                users = repo.GetByName(logon.UserName);
            }
            if (users.Password.Equals(logon.Password))
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Success" }));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "Failure" }));
            }
        }
 public ActionResult ValidateLogin(Logon user)
 {
     if (ModelState.IsValid)
     {
         Logon users = null;
         using (MySqlConnection conn = DBUtils.GetConnection())
         {
             LogonRepository repo = new LogonRepository(conn);
             users = repo.GetByName(user.UserName);
         }
         if (users.Password.Equals(user.Password))
         {
             context.SetAuthenticationToken(user.UserName.ToString(), false, user);
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError(string.Empty, "Invalid Login Information.");
             return(View("Login", user));
         }
     }
     return(View("Login", user));
 }