public ActionResult InvitationRequest() { LoginModel objLoginModel = new LoginModel(); objLoginModel.FirstName = ""; objLoginModel.LastName = ""; objLoginModel.Email = ""; return View(objLoginModel); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { if (!model.RememberMe) { if (Request.Cookies["CLU"] != null) { DeleteCookieRememberMe(); } } if (Request.Cookies["CLU"] != null) { model.RememberMe = true; model.Username = Request.Cookies["CLU"].Value.ToString(); } string AuthenticationStatus = String.Empty; _connectSession = new ConnectSession(APPLICATION_KEY, SECRET_KEY); _connectSession.Logout(); _connectSession.Login(); //Check User Is Login in with Facebook if (_connectSession.IsConnected()) { AuthenticationStatus = ManageFacebook(); if (AuthenticationStatus == "true") { return Redirect("~/Profile/CurrentCourses"); //return Redirect("~/CourseHome/CourseHome?CourseID=10&IsTopVoted=0"); } else { if (!string.IsNullOrEmpty(model.Password)) { model.Password = Cryptography.Cryptography.Encrypt(model.Password); AuthenticationStatus = AuthenticateUser(model.Username, model.Password, model.RememberMe); } if (AuthenticationStatus == "true") { return Redirect("~/Profile/CurrentCourses"); //return Redirect("~/CourseHome/CourseHome?CourseID=10&IsTopVoted=0"); } else { ViewData["Message"] = string.Format("Facebook user does not exist !"); WebCookies WebCookieInstance = new WebCookies(); WebCookieInstance.ClearCookies(); FormsAuthentication.SignOut(); return View(model); } } } else { if (!string.IsNullOrEmpty(model.Password)) { model.Password = Cryptography.Cryptography.Encrypt(model.Password); AuthenticationStatus = AuthenticateUser(model.Username, model.Password, model.RememberMe); } if (AuthenticationStatus == "true") { return Redirect("~/Profile/CurrentCourses"); //return Redirect("~/CourseHome/CourseHome?CourseID=10&IsTopVoted=0"); } else { if ((model.Username != null || model.Password != null)) { if (Request.Cookies["CLU"] != null) { model.RememberMe = true; model.Username = Request.Cookies["CLU"].Value.ToString(); if (AuthenticationStatus == "false" && model.Password != null) { ViewData["Message"] = string.Format("Invalid username/password combination. Please try again."); } } else { ViewData["Message"] = string.Format("Invalid username/password combination. Please try again."); } } WebCookies WebCookieInstance = new WebCookies(); WebCookieInstance.ClearCookies(); FormsAuthentication.SignOut(); return View(model); } } } else { //ViewData["Message"] = string.Format("Invalid username/password combination. Please try again."); return View(model); } }
public string AuthenticateUser(string UserName, string Password, bool RememberME) { DataSet objDS = new DataSet(); LoginModel objLoginModel = new LoginModel(); AccountsDAL objAccountsDAL = new AccountsDAL(); objDS = objAccountsDAL.CheckAccountExists(UserName, Password); if (objDS.Tables.Count > 0) { DataTable dataTable = objDS.Tables[0]; if (dataTable.Rows.Count > 0) { List<LoginModel> _LoginList = new List<LoginModel>(); foreach (DataRow row in dataTable.Rows) { objLoginModel = new LoginModel { AccountID = Convert.ToInt64(row["AccountID"]), Username = row["UserName"].ToString(), Password = row["password"].ToString(), AccountTitle = row["AccountTitle"].ToString(), ProfileImage = row["ProfileImage"].ToString(), }; _LoginList.Add(objLoginModel); } objLoginModel = _LoginList.Single(); } else { return "false"; } } if (objLoginModel.AccountID > 0) { if (RememberME) { SetCookieRememberMe("CLU", objLoginModel.Username.ToString(), DateTime.Now, new TimeSpan(30, 0, 0, 0)); } SetCookie("ID", objLoginModel.AccountID.ToString()); SetCookie("AccountTitle", objLoginModel.AccountTitle); SetCookie("PImage", objLoginModel.ProfileImage); FormsAuthentication.SetAuthCookie(objLoginModel.Username, true); FormsAuthentication.RedirectFromLoginPage(objLoginModel.Username, false); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, "user", DateTime.Now, DateTime.Now.AddMinutes(3), true, "fabiano!", FormsAuthentication.FormsCookiePath); // Create encrypted cookie string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } // Set and done Response.Cookies.Add(cookie); //Necessary, otherwise UserData property gets lost return "true"; } if (objLoginModel.AccountID < 1) { return "false"; } return String.Empty; }
// // GET: /Login/ public ActionResult Index() { //return View(); LoginModel model = new LoginModel(); if (ModelState.IsValid) { return View(model); //return RedirectToAction("Login"); } else { return View(model); } }