public ActionResult Logout() { // Delete login tokens HttpCookie sacredCookie = Request.Cookies[Constants._COOKIE_NAME_]; if (sacredCookie != null) { UserApiProxy.LogoutUser(SSConfiguration.WebApiUrl, Convert.ToInt32(sacredCookie.Values.Get(Constants._COOKIE_USER_ID_))); sacredCookie.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(sacredCookie); } FormsAuthentication.SignOut(); Session.Abandon(); // clear authentication cookie HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, ""); cookie1.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(cookie1); // clear session cookie (not necessary for your current problem but i would recommend you do it anyway) HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", ""); cookie2.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(cookie2); return(RedirectToAction("Index", "Home")); }
public ActionResult Verify(int Id, string Token) { VerifyResponse response = UserApiProxy.VerifyUserRegistration(SSConfiguration.WebApiUrl, Id, Token); if (!response.Success) { // Bad data or something - go home return(RedirectToAction("Index", "Home")); } return(View(response.User)); }
public ActionResult Login(InputUser user, string returnUrl) { LoginResponse response = UserApiProxy.ValidateUser(SSConfiguration.WebApiUrl, user.Email, user.Password); if (response.Success) { // Setup our cookies FormsAuthentication.SetAuthCookie(response.UserToken.ToString(), true); CookieUser cUser = new CookieUser(); cUser.UserId = response.User.Id; cUser.UserName = response.User.Username; cUser.UserToken = response.UserToken.ToString(); HttpCookie sacredCookie = new HttpCookie(Constants._COOKIE_NAME_); sacredCookie.Value = Newtonsoft.Json.JsonConvert.SerializeObject(cUser); sacredCookie.Expires = DateTime.Now.AddDays(3.0); Response.Cookies.Add(sacredCookie); // Setup our session variables SessionInfo.UserId = response.User.Id.ToString(); SessionInfo.UserToken = response.UserToken.ToString(); if (response.AutoLogoutInMinutes > 0) { Session.Timeout = response.AutoLogoutInMinutes; } // Redirect to url or user profile if (returnUrl != null && Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Profile", "User", new { id = response.User.Id })); } } else { user.Errors = new List <string>(); user.Errors.Add(response.Message); } return(View(user)); }
public ActionResult Index(InputUser model, string returnUrl) { RegisterResponse response = UserApiProxy.RegisterUser(SSConfiguration.WebApiUrl, model); if (response.Success) { // Send verification email to user try { using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage( new System.Net.Mail.MailAddress("*****@*****.**", "Sacred System"), new System.Net.Mail.MailAddress(response.RegisteredUser.Email, response.RegisteredUser.Username))) { message.Subject = "Email confirmation"; message.Body = string.Format(@"Dear {0}, <br /><br /> Thank you for registering at Sacred System, please click on the below link to complete your registration. <br /><br /> <a href='{1}' title='User Email Confirm'>{1}</a>", response.RegisteredUser.Username, Url.Action("Verify", "Account", new { Id = response.RegisteredUser.Id, Token = response.RegisteredToken.Token }, Request.Url.Scheme)); message.IsBodyHtml = true; using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)) { smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "setup2Fail"); smtp.EnableSsl = true; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.Timeout = 20000; smtp.Send(message); } } } catch (Exception e) { System.Console.WriteLine(e.Message); } // Go to registration complete page return(RedirectToAction("RegistrationComplete", "Account", new { email = response.RegisteredUser.Email })); } else { model.Errors = response.Errors; } return(View(model)); }