Пример #1
0
 /// <summary>
 /// Creates a new profile and persists it to the database.
 /// </summary>
 /// <param name="username">The profile's username.</param>
 /// <param name="password">The profile's password.</param>
 /// <param name="cookies">Session cookies provided by SA's servers.</param>
 /// <returns>A persisted UserProfile; null if the persistence fails.</returns>
 public AwfulProfile CreateProfile(string username, string password, IList<Cookie> cookies)
 {
     AwfulProfile profile = null;
     try
     {
         profile = new AwfulProfile();
         profile.Username = username;
         profile.Password = password;
         foreach (var cookie in cookies)
         {
             var token = new AwfulAuthenticationToken(cookie);
             profile.Tokens.Add(token);
         }
         // insert and submit changes to database
         this._context.Profiles.InsertOnSubmit(profile);
         this._context.SubmitChanges();
     }
     catch (Exception ex)
     {
         Event.Logger.AddEntry("An error occured while creating a profile:", ex);
         profile = null;
     }
     return profile;
 }
Пример #2
0
 private void OnTokenRemove(AwfulAuthenticationToken token)
 {
     token.AwfulProfile = null;
 }
Пример #3
0
 private void OnTokenAdd(AwfulAuthenticationToken token)
 {
     token.AwfulProfile = this;
 }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="cookies"></param>
        /// <returns></returns>
        public AwfulProfile SaveAuthenticationCookiesToProfile(AwfulProfile profile, IList<Cookie> cookies)
        {
            AwfulProfile profileToUpdate = null;
            try
            {
                profileToUpdate = this.GetProfileByUsername(profile.Username);
                if (profileToUpdate != null)
                {
                    foreach (var cookie in cookies)
                    {
                        var token = new AwfulAuthenticationToken(cookie);
                        profileToUpdate.Tokens.Add(token);
                    }
                }

                this._context.SubmitChanges();
            }
            catch (Exception ex)
            {
                Event.Logger.AddEntry("Error while saving cookies to profile:", ex);
                profileToUpdate = null;
            }
            return profileToUpdate;
        }