public ActionResult LinkedinLogin(string type) { var response = new ResponseModel<LoginResponse>(); String AbsoluteUri = Request.Url.AbsoluteUri; string oauth_token = Request.QueryString["oauth_token"]; string oauth_verifier = Request.QueryString["oauth_verifier"]; String refKey = Request.QueryString["refKey"]; string authLink = string.Empty; if (oauth_token != null && oauth_verifier != null) { var linkedinApiDataResponse = _db.linkedinAuths.SingleOrDefault(x => x.oauth_Token == oauth_token); if (linkedinApiDataResponse != null) { GetAccessToken(oauth_token, linkedinApiDataResponse.oauth_TokenSecret, oauth_verifier); String UserDetailString = RequestProfile(_oauth.Token, _oauth.TokenSecret, oauth_verifier); var linkedinUserDetails = JsonConvert.DeserializeObject<linkedinUserDataWrapper>(Convert.ToString(UserDetailString)); _db.linkedinAuths.Attach(linkedinApiDataResponse); _db.linkedinAuths.Remove(linkedinApiDataResponse); var ifUserAlreadyRegistered = _db.Users.SingleOrDefault(x => x.Username == linkedinUserDetails.emailAddress); if (ifUserAlreadyRegistered != null) { var data = new Dictionary<string, string>(); data["Username"] = ifUserAlreadyRegistered.Username; data["Password"] = ifUserAlreadyRegistered.Password; data["userGuid"] = ifUserAlreadyRegistered.guid; var encryptedData = EncryptionClass.encryptUserDetails(data); response.Payload = new LoginResponse(); response.Payload.UTMZK = encryptedData["UTMZK"]; response.Payload.UTMZV = encryptedData["UTMZV"]; response.Payload.TimeStamp = DateTime.Now.ToString(CultureInfo.InvariantCulture); response.Payload.Code = "210"; response.Status = 210; response.Message = "user Login via facebook"; try { ifUserAlreadyRegistered.KeepMeSignedIn = "true";//keepMeSignedIn.Equals("true", StringComparison.OrdinalIgnoreCase) ? "true" : "false"; ifUserAlreadyRegistered.Locked = Constants.status_false; _db.SaveChanges(); var session = new M2ESession(ifUserAlreadyRegistered.Username); TokenManager.CreateSession(session); response.Payload.UTMZT = session.SessionId; ViewBag.umtzt = response.Payload.UTMZT; ViewBag.umtzk = response.Payload.UTMZK; ViewBag.umtzv = response.Payload.UTMZV; return View(); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Payload.Code = "500"; return Json(response, JsonRequestBehavior.AllowGet); } } else { //add user to database. var guid = Guid.NewGuid().ToString(); if (linkedinUserDetails.pictureUrl == null || linkedinUserDetails.pictureUrl == "") linkedinUserDetails.pictureUrl = Constants.NA; // if picture is not available. var user = new User { Username = linkedinUserDetails.emailAddress, Password = EncryptionClass.Md5Hash(Guid.NewGuid().ToString()), Source = "linkedin", isActive = "true", Type = "user", guid = Guid.NewGuid().ToString(), fixedGuid = Guid.NewGuid().ToString(), FirstName = linkedinUserDetails.firstName, LastName = linkedinUserDetails.lastName, gender = Constants.NA, ImageUrl = linkedinUserDetails.pictureUrl }; _db.Users.Add(user); try { _db.SaveChanges(); var data = new Dictionary<string, string>(); data["Username"] = user.Username; data["Password"] = user.Password; data["userGuid"] = user.guid; var encryptedData = EncryptionClass.encryptUserDetails(data); response.Payload = new LoginResponse(); response.Payload.UTMZK = encryptedData["UTMZK"]; response.Payload.UTMZV = encryptedData["UTMZV"]; response.Payload.TimeStamp = DateTime.Now.ToString(CultureInfo.InvariantCulture); response.Payload.Code = "210"; response.Status = 210; response.Message = "user Login via linkedin"; try { var session = new M2ESession(user.Username); TokenManager.CreateSession(session); response.Payload.UTMZT = session.SessionId; ViewBag.umtzt = response.Payload.UTMZT; ViewBag.umtzk = response.Payload.UTMZK; ViewBag.umtzv = response.Payload.UTMZV; ViewBag.isNewUser = "******"; var signalRHub = new SignalRHub(); string totalProjects = ""; string successRate = ""; string totalUsers = _db.Users.Count().ToString(CultureInfo.InvariantCulture); string projectCategories = ""; new UserMessageService().SendUserNotificationForAccountVerificationSuccess( user.Username, user.Type ); var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories); return View(); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!"; } } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!!"; } } } } else { authLink = CreateAuthorization(); var linkedInApiData = new linkedinAuth { oauth_Token = _oauth.Token, oauth_TokenSecret = _oauth.TokenSecret, oauth_verifier = "" }; _db.linkedinAuths.Add(linkedInApiData); try { _db.SaveChanges(); Response.Redirect(authLink); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!!"; } } ViewBag.code = response.Status; return View(); }
public JsonResult saveData() { var deviceId = Request.QueryString["deviceId"]; if (deviceId != null) { var linkedInApiData = new linkedinAuth { oauth_Token = Constants.NA, oauth_TokenSecret = deviceId, oauth_verifier = "" }; _db.linkedinAuths.Add(linkedInApiData); try { _db.SaveChanges(); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); } } return Json("success",JsonRequestBehavior.AllowGet); }
public ActionResult LinkedinLoginGetRedirectUri(string type) { var response = new ResponseModel<LoginResponse>(); String AbsoluteUri = Request.Url.AbsoluteUri; string oauth_token = Request.QueryString["oauth_token"]; string oauth_verifier = Request.QueryString["oauth_verifier"]; String refKey = Request.QueryString["refKey"]; string authLink = string.Empty; if (oauth_token == null || oauth_verifier == null) { authLink = CreateAuthorization(); var linkedInApiData = new linkedinAuth { oauth_Token = _oauth.Token, oauth_TokenSecret = _oauth.TokenSecret, oauth_verifier = "" }; _db.linkedinAuths.Add(linkedInApiData); try { _db.SaveChanges(); response.Status = 199; response.Message = authLink; //Response.Redirect(authLink); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!!"; } } return Json(response, JsonRequestBehavior.AllowGet); }