public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("STATSMIX_URL"))) { // STATSMIX_URL is populated by AppHarbor, so we must be in deployment; log this event to our StatsMix metrics StatsMix.Client smClient = new StatsMix.Client("3cc98589f0c307a4096b"); Dictionary <string, string> properties = new Dictionary <string, string>(0); Dictionary <string, string> meta = new Dictionary <string, string>(1); meta.Add("User", model.UserName); smClient.track("Login", 1, properties, meta); } FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "App")); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public HttpResponseMessage Post(ProjectSite value) { if (!User.Identity.IsAuthenticated) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } if (String.IsNullOrEmpty(value.PolygonGeometry)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("STATSMIX_URL"))) { // STATSMIX_URL is populated by AppHarbor, so we must be in deployment; log this event to our StatsMix metrics StatsMix.Client smClient = new StatsMix.Client("3cc98589f0c307a4096b"); Dictionary <string, string> properties = new Dictionary <string, string>(0); Dictionary <string, string> meta = new Dictionary <string, string>(1); meta.Add("User", User.Identity.Name); smClient.track("Add Site", 1, properties, meta); } value.UserId = User.Identity.Name; ProjectSite site = _db.Add(value); var response = Request.CreateResponse <ProjectSite>(HttpStatusCode.Created, site); string uri = Url.Route(null, new { id = site.Id }); response.Headers.Location = new Uri(Request.RequestUri, uri); return(response); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("STATSMIX_URL"))) { // STATSMIX_URL is populated by AppHarbor, so we must be in deployment; log this event to our StatsMix metrics StatsMix.Client smClient = new StatsMix.Client("3cc98589f0c307a4096b"); smClient.track("Register", 1); } FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); return(RedirectToAction("Index", "App")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }