/// <summary> /// Creates a UserInfo class from the User class. /// </summary> /// <param name="user">User who's data is used to create the UserInfo.</param> /// <returns>UserInfo created from User.</returns> public static UserInfo FromUser(User user) { Contract.Requires<ArgumentNullException>(user != null); return new UserInfo { UserId = user.UserId, Username = user.Username, Email = user.Email, FullName = user.FullName }; }
/// <summary> /// Create a new User object. /// </summary> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="username">Initial value of the Username property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="fullName">Initial value of the FullName property.</param> public static User CreateUser(global::System.Int32 userId, global::System.String username, global::System.String email, global::System.String fullName) { User user = new User(); user.UserId = userId; user.Username = username; user.Email = email; user.FullName = fullName; return user; }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Issues the FormsAuthenticationTicket to let ASP.NET know that a user is logged in. /// </summary> /// <param name="user">User that has logged in.</param> private void IssueFormsAuthenticationTicket(User user, bool? rememberMe) { // We need to make a FormsAuthenticationTicket. // To store UserInfo data in it we use the 2nd overload. // Note that if rememberMe is false the cookie is stored in the session and will expire when the session is over. FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, user.Username, DateTime.Now, DateTime.Now.AddDays(14), rememberMe ?? false, UserInfo.FromUser(user).ToString()); // Now we encrypt the ticket so no one can read it... string encTicket = FormsAuthentication.Encrypt(ticket); // ...make a cookie and add it. ASP.NET will now know that our user is logged in. Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); }
public ActionResult Register(User user, string identifier, string returnUrl, bool rememberMe) { //The registration form has been submitted try { if (ModelState.IsValid) { OpenId openid = new OpenId { OpenIdUrl = identifier, User = user }; users.AddOpenId(openid); users.SaveChanges(); // Now let's login out user to out application IssueFormsAuthenticationTicket(user, rememberMe); // We're done, let's get back to where we started from. if (string.IsNullOrEmpty(returnUrl)) return RedirectToAction("Index", "Home"); else return Redirect(returnUrl); } var registrationModel = new RegistrationViewModel(identifier) { Username = user.Username, Email = user.Email, FullName = user.FullName, ReturnUrl = returnUrl }; return View(registrationModel); } catch { var registrationModel = new RegistrationViewModel(identifier) { Username = user.Username, Email = user.Email, FullName = user.FullName, ReturnUrl = returnUrl }; return View(registrationModel); } }
public ActionResult Edit(User user) { try { // Let's get the user with this id var u = users.GetUser(user.UserId); // Let's try and update it. if (TryUpdateModel<User>(u)) { // If the update goes through we need to save the changes to the database... users.SaveChanges(); // ... and return the user to the User/Index return RedirectToAction("Index"); } ModelState.AddModelError("general_error", "Something went wrong while updating the data."); } catch (Exception e) { ModelState.AddModelError("general_error", e); } // Whatever goes wrong we redisplay the user edit form with as much data as we can get. return View(user); }