Ejemplo n.º 1
0
 public void Update(ForumAccessToken token)
 {
     this.token = token;
     this.Username = token.Username;
     this.UserTokens.Clear();
     foreach (var cookie in token.Cookies)
     {
         this.UserTokens.Add(new UserToken(cookie));
     }
 }
Ejemplo n.º 2
0
        public ForumAccessToken AsForumAccessToken()
        {
            if (this.token == null)
            {
                ForumAccessToken token = new ForumAccessToken();
                token.Username = this.Username;
                foreach (var userToken in this.UserTokens)
                {
                    token.Cookies.Add(userToken.ToCookie());
                }

                this.token = token;
            }

            return this.token;
        }
Ejemplo n.º 3
0
        public async Task<ThreadFormResponse> SubmitAsync(ForumAccessToken token)
        {
            ThreadFormResponse response = null;
            this.WhileBusy(true);

            try
            {
                response = await submit(token);
                if (response.Success)
                {
                    this.OnSuccess();
                }
                else
                    this.OnFailure(new InvalidOperationException("post submit failed."));
            }
            catch (Exception ex) { this.OnFailure(ex); }
            finally { this.WhileBusy(false); }
            return response;
        }
Ejemplo n.º 4
0
 private Task<ThreadFormResponse> SubmitPostAsync(ForumAccessToken token)
 {
     return thread.ReplyAsync(this.message, token);
 }
Ejemplo n.º 5
0
 private Task<ThreadFormResponse> SubmitFormAsync(ForumAccessToken token)
 {
     if (form != null)
     {
         form.Message = this.message;
         return form.SubmitAsync(token);
     }
     else
     {
         return SubmitPostAsync(token);
     }
 }
Ejemplo n.º 6
0
 public UserAccount(ForumAccessToken token)
     : this()
 {
     this.Update(token);
 }
Ejemplo n.º 7
0
        public static async Task<ForumAccessToken> AuthenticateAsync(string username, string password)
        {
            var handler = CreateHttpClientHandler(null);
            var loginClient = CreateHttpClient(handler);

            HttpContent content = new FormUrlEncodedContent(
                new KeyValuePair<string,string>[]{
                    new KeyValuePair<string, string>("action", "login"),
                    new KeyValuePair<string, string>("username", username),
                    new KeyValuePair<string, string>("password", password),
                    new KeyValuePair<string, string>("next", "/")
                });

            string postData = await content.ReadAsStringAsync();
            postData = postData.Replace("!", "%21");

            content = new StringContent(postData);
            content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            content.Headers.Add("Origin", "http://forums.somethingawful.com");
         
            var response = await loginClient.PostAsync("/account.php", content);
            response.EnsureSuccessStatusCode();
           
            ForumAccessToken user = new ForumAccessToken();
            user.Username = username;

            // extract cookies
            var cookieUri = new Uri(COOKIE_DOMAIN_URL, UriKind.Absolute);
            var cookieCollection = handler.CookieContainer.GetCookies(cookieUri);
            user.Cookies = new List<Cookie>(cookieCollection.Count);

            // fix domain issue -> .forums.somethingawful.com to forums.somethingawful.com
            foreach (Cookie cookie in cookieCollection)
            {
                var fixedCookie = new Cookie(
                    cookie.Name,
                    cookie.Value,
                    "/",
                    DOMAIN_FIX);

                user.Cookies.Add(fixedCookie);
                handler.CookieContainer.Add(new Uri(BASE_URL), fixedCookie);
            }

            AwfulWebClient awc = new AwfulWebClient(user, loginClient);
            return user;
        }
Ejemplo n.º 8
0
 private AwfulWebClient(ForumAccessToken metadata)
 {
     this.CurrentUser = metadata;
     this.CurrentUser.Client = CreateHttpClient(CreateHttpClientHandler(metadata.Cookies));
 }
Ejemplo n.º 9
0
 private AwfulWebClient(ForumAccessToken metadata, HttpClient client) {
     this.CurrentUser = metadata;
     this.CurrentUser.Client = client;
 }
Ejemplo n.º 10
0
 public AccessTokenMessage()
 {
     this.Token = null;
 }