Exemplo n.º 1
0
        // GET: Auth
        public async Task <ActionResult> fb(string code, string useremail)
        {
            var base64EncodedBytes = System.Convert.FromBase64String(useremail);
            var realuseremail      = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);

            using (var client = new HttpClient())
            {
                var redirecturl = "http://webapplication16742.azurewebsites.net/auth/fb/" + useremail;
                var s1          = await client.GetStringAsync("https://graph.facebook.com/v2.3/oauth/access_token?client_id=619387381484849&redirect_uri=" + redirecturl + "&client_secret=1f22ecd5cfa27759fbf126531994531c&code=" + code);

                TokenClass token = JsonConvert.DeserializeObject <TokenClass>(s1);

                var s2 = await client.GetStringAsync("https://graph.facebook.com/v2.3/me?access_token=" + token.access_token);

                var fbme = JsonConvert.DeserializeObject <FbMe>(s2);

                var ac = new WebApplication1.Models.AccountInfo.SubAccount();
                ac.provider  = "fb";
                ac.token     = token.access_token;
                ac.useremail = realuseremail;
                ac.userid    = fbme.id;
                ac.username  = fbme.name;

                if (!TokenController.addTokenInternal(ac))
                {
                    return(HttpNotFound());
                }
            }

            return(Redirect("/home/index?user=" + realuseremail));
        }
Exemplo n.º 2
0
        public static bool addTokenInternal(WebApplication1.Models.AccountInfo.SubAccount account)
        {
            using (SqlConnection connection =
                       new SqlConnection(HomeController.connectString))
            {
                // Create the Command and Parameter objects.
                string     queryString = "insert into mTable values (@useremail,@provider,@token,@userid, NEWID(),@username)";
                SqlCommand command     = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@useremail", account.useremail);
                command.Parameters.AddWithValue("@token", account.token);
                command.Parameters.AddWithValue("@userid", account.userid);
                command.Parameters.AddWithValue("@provider", account.provider);
                command.Parameters.AddWithValue("@username", account.username);

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
 public IHttpActionResult addtoken(WebApplication1.Models.AccountInfo.SubAccount account)
 {
     if (addTokenInternal(account))
     {
         return(Ok());
     }
     return(NotFound());
 }
Exemplo n.º 4
0
        public static AccountInfo getAllInternal(string useremail)
        {
            var ret = new AccountInfo();

            ret.useremail   = useremail;
            ret.accountlist = new List <AccountInfo.SubAccount>();
            using (SqlConnection connection =
                       new SqlConnection(HomeController.connectString))
            {
                // Create the Command and Parameter objects.
                string     queryString = "select * FROM dbo.mTable WHERE useremail=@useremail";
                SqlCommand command     = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@useremail", useremail);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    var tp = new WebApplication1.Models.AccountInfo.SubAccount();
                    tp.provider = reader.GetString(1);
                    tp.token    = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                    {
                        tp.userid = reader.GetString(3);
                    }

                    tp.id = reader.GetString(4);
                    if (!reader.IsDBNull(5))
                    {
                        tp.username = reader.GetString(5);
                    }

                    ret.accountlist.Add(tp);
                }
                reader.Close();
            }

            return(ret);
        }