/// <summary> /// Handles the Authenticate event of the Login1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="AuthenticateEventArgs" /> instance containing the event data.</param> protected void Login1_Authenticate([NotNull] object sender, [NotNull] AuthenticateEventArgs e) { e.Authenticated = false; var userData = new UserAuthentication(this.Login1.UserName, this.Login1.Password); var realUserName = userData.IsAuthenticated(); if (realUserName.IsNotSet()) { return; } this.Login1.UserName = realUserName; e.Authenticated = true; }
public HttpResponseMessage Login(LoginModel userData) { Contract.Requires(userData != null); var userToAuthenticate = new UserAuthentication(userData.Username, userData.Password); var realUserName = userToAuthenticate.IsAuthenticated(); if (!string.IsNullOrEmpty(realUserName)) { var ticket = new FormsAuthenticationTicket(1, userData.Username, DateTime.Now, DateTime.Now.AddMinutes(30), false, "", "/"); var strEncTicket = FormsAuthentication.Encrypt(ticket); var authCookie = new HttpCookie(".YAFNET_Authentication", strEncTicket) {Path = "/"}; HttpContext.Current.Response.Cookies.Add(authCookie); var usersProfile = UserData.GetProfileContext(UserData.GetUserIdFromDisplayName(realUserName)); return Request.CreateResponse(HttpStatusCode.Created, usersProfile); } return Request.CreateResponse(HttpStatusCode.Unauthorized); }