Esempio 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));
     }
 }
Esempio 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;
        }
        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;
        }
 private Task<ThreadFormResponse> SubmitPostAsync(ForumAccessToken token)
 {
     return thread.ReplyAsync(this.message, token);
 }
 private Task<ThreadFormResponse> SubmitFormAsync(ForumAccessToken token)
 {
     if (form != null)
     {
         form.Message = this.message;
         return form.SubmitAsync(token);
     }
     else
     {
         return SubmitPostAsync(token);
     }
 }
Esempio n. 6
0
 public UserAccount(ForumAccessToken token)
     : this()
 {
     this.Update(token);
 }
Esempio 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;
        }
Esempio n. 8
0
 private AwfulWebClient(ForumAccessToken metadata)
 {
     this.CurrentUser = metadata;
     this.CurrentUser.Client = CreateHttpClient(CreateHttpClientHandler(metadata.Cookies));
 }
Esempio n. 9
0
 private AwfulWebClient(ForumAccessToken metadata, HttpClient client) {
     this.CurrentUser = metadata;
     this.CurrentUser.Client = client;
 }
Esempio n. 10
0
 public AccessTokenMessage()
 {
     this.Token = null;
 }