public Guid RegisterSocial(SocialRegistration item) { var result = default(Guid); using (var db = new RegistrationContext()) { item.Guid = (item.Guid == default(Guid)) ? Guid.NewGuid() : item.Guid; var socialRegistration = db.SocialRegistrations.Where(mr => mr.Guid == item.Guid).SingleOrDefault(); if (socialRegistration == null) { item.SocialRegistrationId = default(int); db.Entry <SocialRegistration>(item).State = EntityState.Added; } else { item.SocialRegistrationId = socialRegistration.SocialRegistrationId; db.Entry <SocialRegistration>(item).State = EntityState.Modified; } db.SaveChanges(); result = socialRegistration.Guid; } return(result); }
public Login Registration_ThirdParty(SocialRegistration ouser) { try { StreamReader readStream; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + GeneralBLL.Service_Link + "/Services/AccountService.svc/RegisterThirdParty"); httpWebRequest.Method = "POST"; httpWebRequest.ContentType = @"application/json; charset=utf-8"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = new JavaScriptSerializer().Serialize(ouser); streamWriter.Write(json); } HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); readStream = new StreamReader(httpResponse.GetResponseStream()); var serializer = new DataContractJsonSerializer(typeof(Login)); Login obj = serializer.ReadObject(readStream.BaseStream) as Login; return(obj); } catch (Exception ex) { return(null); } }
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")); } }
public Login AddMembers_ThirdParty(SocialRegistration obj) { try { U_USR_LgnDAL ologonDAL = new U_USR_LgnDAL(); U_USR_MASTERDAL oMstDAL = new U_USR_MASTERDAL(); U_USR_Lgn Lgnobj = new U_USR_Lgn(); U_USR_MASTER Mstobj = new U_USR_MASTER(); string user_id = ologonDAL.CheckLoginId_Exist(obj.Id); if (string.IsNullOrEmpty(user_id)) { Mstobj.Usr_Id = Guid.NewGuid().ToString(); Mstobj.Usr_role_Id = ""; Mstobj.Date_Of_Birth = DateTime.Now; Mstobj.First_Name = obj.First_Name; Mstobj.Alt_Email_Id = string.Empty; Mstobj.Gender = string.Empty; Mstobj.Is_married = 0; Mstobj.Last_Name = string.Empty; Mstobj.Media_Id_Img = "1"; Mstobj.Address_Id = "1"; Mstobj.Rating = string.Empty; Mstobj.Updated_by = string.Empty; Mstobj.Updated_Date = DateTime.Now; Mstobj.Wed_anniversary = DateTime.Now; Mstobj.About_member = string.Empty; Mstobj.Created_by = string.Empty; Mstobj.Created_Date = DateTime.Now; var status = oMstDAL.InsertU_USR_MASTER(Mstobj); if (status) { Lgnobj.Login_Id = obj.Id; Lgnobj.Login_status = 2; Lgnobj.Email_ID = obj.Email_Id; Lgnobj.Mobile_Number = obj.Phone_No; Lgnobj.Pwd = string.Empty; Lgnobj.Created_by = string.Empty; Lgnobj.Updated_by = string.Empty; Lgnobj.Updated_Date = DateTime.Now; Lgnobj.Created_Date = DateTime.Now; Lgnobj.Last_Login_Date = DateTime.Now; Lgnobj.Ip_Address = string.Empty; Lgnobj.Usr_Mst_Id = Mstobj.Usr_Id; status = ologonDAL.InsertU_USR_Lgn(Lgnobj); } if (status == true) { Login ologin = new Login(); user_id = ologonDAL.CheckLoginId_Exist(obj.Id); ologin.First_Name = obj.First_Name; ologin.Id = user_id; return(ologin); } else { return(null); // indicates unsuccessfull } } else { Login ologin = new Login(); ologin.First_Name = obj.First_Name; ologin.Id = user_id; return(ologin); // indicates LoginId already exists } } catch { return(null); // indicates unsuccessfull } }
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")); }