/// <summary>
 /// Converts the user entered data into a User object.
 /// </summary>
 /// <param name="encryption">Business class used to encrypt
 /// the password entered by the user.</param>
 /// <returns>User object made up of this data.</returns>
 public virtual User ToUser(IEncryption encryption)
 {
     var user = new User();
     user.Username = Username;
     user.MakeAdmin();
     user.SetPassword(encryption.Encrypt(Password));
     return user;
 }
 /// <summary>
 /// Sets data about the User onto the Session
 /// that is stored on the current context.
 /// </summary>
 /// <param name="user">User that the data being
 /// set on the Session.</param>
 public void SetSessionData(User user)
 {
     _httpContextProvider.Session["LoggedInAs"] = user.Username;
 }
        /// <summary>
        /// Authenticates the session, which changes the clients
        /// state to logged in.
        /// </summary>
        /// <param name="user">User that has signed in.</param>
        /// <param name="remember">Whether the user should be
        /// remembered next time they visit.</param>
        public void Start(User user, bool remember)
        {
            var roles = string.Join(",", user.Roles.ToArray());
            var expireDate = GetExpiryDate(remember);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, CreateEncryptedTicket(user.Id.ToString(), roles, expireDate, remember));

            if (remember)
                cookie.Expires = expireDate;

            _httpContextProvider.Response.Cookies.Add(cookie);

            SetSessionData(user);
        }
 /// <summary>
 /// Inserts the user into the database, thus
 /// creating a new user in the system.
 /// </summary>
 /// <param name="user">User that is being created.</param>
 /// <returns>True if successful, otherwise false.</returns>
 public void Create(User user)
 {
     _db.Users.Insert(user);
 }