Esempio n. 1
0
        public ActionResult FacebookLogin(string code)
        {
            try
            {
                string       data         = FaceBookConnect.Fetch(code, "me");
                FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize <FaceBookUser>(data);
                faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type=large", faceBookUser.Id);

                SocialRegistration obj = new SocialRegistration();
                obj.Id          = faceBookUser.Id;
                obj.Email_Id    = string.IsNullOrEmpty(faceBookUser.Email)? faceBookUser.Id + "@BAG.com": faceBookUser.Email;
                obj.First_Name  = faceBookUser.Name;
                obj.Phone_No    = string.Empty;
                obj.Profile_Pic = faceBookUser.PictureUrl;
                AccountsBLL obll   = new AccountsBLL();
                Login       status = obll.Registration_ThirdParty(obj);
                if (status != null)
                {
                    if (!string.IsNullOrEmpty(status.Id))
                    {
                        Session["UserId"]   = status.Id;
                        Session["UserName"] = status.First_Name;
                        UpdateEventInvites();
                    }
                    return(RedirectToAction("Index", "Dashboard"));
                }
                else
                {
                    return(RedirectToAction("Index", "Account"));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 2
0
        public ActionResult GoogleLogin()
        {
            string googleplus_client_id     = "936649599657-s9akus1uv18lo7b103ji7t3cu1ljlfjb.apps.googleusercontent.com";
            string googleplus_client_sceret = "w5nmQnac-A2gBLR8dh2YWGqk";
            string googleplus_redirect_url  = "http://" + Global.MainLink + "/Account/GoogleLogin";
            string Parameters;
            var    url = Request.Url.Query;

            if (url != "")
            {
                string   queryString    = url.ToString();
                char[]   delimiterChars = { '=' };
                string[] words          = queryString.Split(delimiterChars);
                string   code           = words[1];

                if (code != null)
                {
                    //get the access token
                    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
                    webRequest.Method = "POST";
                    Parameters        = "code=" + code + "&client_id=" + googleplus_client_id + "&client_secret=" + googleplus_client_sceret + "&redirect_uri=" + googleplus_redirect_url + "&grant_type=authorization_code";
                    byte[] byteArray = Encoding.UTF8.GetBytes(Parameters);
                    webRequest.ContentType   = "application/x-www-form-urlencoded";
                    webRequest.ContentLength = byteArray.Length;
                    Stream postStream = webRequest.GetRequestStream();
                    // Add the post data to the web request
                    postStream.Write(byteArray, 0, byteArray.Length);
                    postStream.Close();

                    WebResponse response = webRequest.GetResponse();
                    postStream = response.GetResponseStream();
                    StreamReader reader             = new StreamReader(postStream);
                    string       responseFromServer = reader.ReadToEnd();

                    GooglePlusAccessToken serStatus = JsonConvert.DeserializeObject <GooglePlusAccessToken>(responseFromServer);

                    if (serStatus != null)
                    {
                        string accessToken = string.Empty;
                        accessToken = serStatus.access_token;

                        if (!string.IsNullOrEmpty(accessToken))
                        {
                            string         JSONDATA       = "";
                            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(@"https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accessToken);
                            httpWebRequest.Method      = "GET";
                            httpWebRequest.ContentType = @"application/json; charset=utf-8";

                            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                            {
                                JSONDATA = streamReader.ReadToEnd();
                            }
                            var                json_serializer = new JavaScriptSerializer();
                            GooglePlusLogin    Profile         = JsonConvert.DeserializeObject <GooglePlusLogin>(JSONDATA);
                            SocialRegistration obj             = new SocialRegistration();
                            obj.Id          = Profile.id;
                            obj.Email_Id    = string.IsNullOrEmpty(Profile.email)?Profile.id + "@BAG.com": Profile.email;
                            obj.First_Name  = Profile.name;
                            obj.Phone_No    = string.Empty;
                            obj.Profile_Pic = Profile.picture;
                            AccountsBLL obll   = new AccountsBLL();
                            Login       status = obll.Registration_ThirdParty(obj);
                            if (status != null)
                            {
                                if (!string.IsNullOrEmpty(status.Id))
                                {
                                    Session["UserId"]   = status.Id;
                                    Session["UserName"] = status.First_Name;
                                    UpdateEventInvites();
                                    return(RedirectToAction("Index", "Dashboard"));
                                }
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Account"));
                            }
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }

            return(View("Index"));
        }