Exemple #1
0
        public ActionResult Index(string code, string state)
        {
            if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(state))
            {
                return(View());
            }
            else
            {
                try
                {
                    //Get Accedd Token
                    var client  = new RestClient("https://www.linkedin.com/oauth/v2/accessToken");
                    var request = new RestRequest(Method.POST);
                    request.AddParameter("grant_type", "authorization_code");
                    request.AddParameter("code", code);
                    request.AddParameter("redirect_uri", "http://avajobs.azurewebsites.net/");
                    request.AddParameter("client_id", "77mx9721mlv2q9");
                    request.AddParameter("client_secret", "IxkBrczENK46dRB1");
                    IRestResponse response = client.Execute(request);
                    var           content  = response.Content;

                    //Fetch AccessToken
                    JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                    LinkedINVM           linkedINVM     = jsonSerializer.Deserialize <LinkedINVM>(content);
                    if (linkedINVM != null)
                    {
                        //Get Profile Details
                        client   = new RestClient("https://api.linkedin.com/v1/people/~?oauth2_access_token=" + linkedINVM.access_token + "&format=json");
                        request  = new RestRequest(Method.GET);
                        response = client.Execute(request);
                        content  = response.Content;

                        jsonSerializer = new JavaScriptSerializer();
                        LinkedINResVM linkedINResVM = jsonSerializer.Deserialize <LinkedINResVM>(content);
                        return(View(linkedINResVM));
                    }
                    else
                    {
                        return(View());
                    }
                }
                catch
                {
                    throw;
                }
            }
        }
Exemple #2
0
        public LinkedINResVM GetProfile(LinkedINVM linkedinvm)
        {
            var StrUrl = "https://api.linkedin.com/v2/me?oauth2_access_token=" + linkedinvm.access_token;

            //Get Profile Details
            RestClient client = new RestClient(StrUrl);

            RestRequest request  = new RestRequest(Method.GET);
            var         response = client.Execute(request);
            var         content  = response.Content;

            HttpContext.Response.Write(content);

            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            LinkedINResVM        linkedinresvm  = jsonSerializer.Deserialize <LinkedINResVM>(content);

            return(linkedinresvm);
        }
Exemple #3
0
        public ActionResult LinkedINAuth(string code, string state)
        {
            string authUrl     = "https://www.linkedin.com/uas/oauth2/accessToken";
            string redirectUrl = "https://localhost:44394//LinkedIn/LinkedINAuth";
            var    sign        = "grant_type=authorization_code" + "&code=" + code + "&redirect_uri=" + HttpUtility.HtmlEncode(redirectUrl) + "&client_id=86r5ibq7rosr97&client_secret=iGs11czgu4ByFndn";
            // var postData = String.Format("grant_type=authorization_code&code={0}&redirect_uri={1}&client_id={2}&client_secret={3}", code, HttpUtility.HtmlEncode(redirectUrl), apiKey, apiSecret);


            HttpWebRequest webRequest = WebRequest.Create(authUrl + "?" + sign) as HttpWebRequest;

            webRequest.Method      = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";

            Stream dataStream = webRequest.GetRequestStream();

            String postData = String.Empty;

            byte[] postArray = Encoding.ASCII.GetBytes(postData);

            dataStream.Write(postArray, 0, postArray.Length);
            dataStream.Close();

            WebResponse response = webRequest.GetResponse();

            dataStream = response.GetResponseStream();


            StreamReader responseReader = new StreamReader(dataStream);
            String       returnVal      = responseReader.ReadToEnd().ToString();

            responseReader.Close();
            dataStream.Close();
            response.Close();

            ////Fetch AccessToken
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            LinkedINVM           linkedINVM     = jsonSerializer.Deserialize <LinkedINVM>(returnVal);

            //Get Profile Details
            LinkedINResVM linkedinresvm = GetProfile(linkedINVM);

            return(View(linkedinresvm));
        }
Exemple #4
0
        //Linked in Plugin

        public ActionResult linkdInReg(string code, string state)
        {
            var ID = "";

            try
            {
                //Get Accedd Token
                var client  = new RestClient("https://www.linkedin.com/oauth/v2/accessToken");
                var request = new RestRequest(Method.POST);
                request.AddParameter("grant_type", "authorization_code");
                request.AddParameter("code", code);
                request.AddParameter("redirect_uri", "https://spotaneedle.com/Account/linkdInReg");
                request.AddParameter("client_id", "772sds0w0tvipg");
                request.AddParameter("client_secret", "6F2xR3Sn93vR0VQX");
                //request.AddParameter("scope", "r_emailaddress");

                IRestResponse response = client.Execute(request);
                var           content  = response.Content;
                //Fetch AccessToken
                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                LinkedINVM           linkedINVM     = jsonSerializer.Deserialize <LinkedINVM>(content);

                //Get Profile Details
                client   = new RestClient("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,summary,picture-url,positions,location,public-profile-url,email-address)?oauth2_access_token=" + linkedINVM.access_token + "&format=json");
                request  = new RestRequest(Method.GET);
                response = client.Execute(request);
                content  = response.Content;


                jsonSerializer = new JavaScriptSerializer();
                LinkedINResVM linkedINResVM = jsonSerializer.Deserialize <LinkedINResVM>(content);

                //linkedINResVM.emailaddress= content.
                //return RedirectToAction("login");

                var result = BaseUtil.checkSocialProfile(linkedINResVM.emailaddress);
                if (result == "NotExists")
                {
                    qendidateList list = new qendidateList();
                    list.qenName       = linkedINResVM.firstName + " " + linkedINResVM.lastName;
                    list.qenEmail      = linkedINResVM.emailaddress;
                    list.qenLinkdInUrl = linkedINResVM.publicprofileurl;
                    list.dataIsCreated = BaseUtil.GetCurrentDateTime();
                    list.dataIsUpdated = BaseUtil.GetCurrentDateTime();

                    list.roleID           = 5;
                    list.isDelete         = false;
                    list.isActive         = true;
                    list.password         = baseClass.GetRandomPasswordString(10);
                    list.qenImage         = linkedINResVM.pictureurl;
                    list.qenPhone         = "9999999999";
                    list.qenAddress       = "some address";
                    list.isMobileVerified = false;
                    list.isEmalVerified   = true;
                    list.qenAddress       = null;
                    list.socialCheck      = true;
                    list.registeredFrom   = "LinkedIN";
                    list.CareerObjective  = linkedINResVM.summary;
                    list.CareerHighlight  = linkedINResVM.headline;
                    db.qendidateLists.Add(list);
                    db.SaveChanges();

                    StreamReader sr        = new StreamReader(Server.MapPath("/Emailer/toCandidateRegistrationSuccess.html"));
                    string       HTML_Body = sr.ReadToEnd();
                    string       newString = HTML_Body.Replace("#name", list.qenName).Replace("#password", list.password);
                    sr.Close();
                    string            To                   = list.qenEmail.ToString();
                    string            mail_Subject         = "Candidate Registration Confirmation ";
                    profileController objprofileController = new profileController();
                    BaseUtil.sendEmailer(To, mail_Subject, newString, "");


                    BaseUtil.SetSessionValue(AdminInfo.UserID.ToString(), Convert.ToString(list.qenID));
                    //BaseUtil.SetSessionValue(AdminInfo.Mobile.ToString(), Convert.ToString(user.qenPhone));
                    BaseUtil.SetSessionValue(AdminInfo.role_id.ToString(), Convert.ToString(list.roleID));
                    BaseUtil.SetSessionValue(AdminInfo.FullName.ToString(), Convert.ToString(list.qenName));
                    ID = BaseUtil.GetSessionValue(AdminInfo.UserID.ToString());
                    BaseUtil.SetSessionValue(AdminInfo.logo.ToString(), Convert.ToString(list.qenImage));
                    BaseUtil.SetSessionValue(AdminInfo.mobileVerified.ToString(), Convert.ToString(list.isMobileVerified));
                    BaseUtil.SetSessionValue(AdminInfo.emailVerified.ToString(), Convert.ToString(list.isEmalVerified));
                }
                else if (result == "Exists")
                {
                    var user = db.qendidateLists.Where(u => u.qenEmail == linkedINResVM.emailaddress).FirstOrDefault();
                    user.socialCheck      = true;
                    user.CareerObjective  = linkedINResVM.summary;
                    user.qenLinkdInUrl    = linkedINResVM.publicprofileurl;
                    user.dataIsUpdated    = BaseUtil.GetCurrentDateTime();
                    user.qenName          = linkedINResVM.firstName + " " + linkedINResVM.lastName;
                    user.registeredFrom   = "LinkedIN";
                    user.isMobileVerified = false;
                    user.isEmalVerified   = true;
                    db.Entry(user).State  = EntityState.Modified;
                    db.SaveChanges();
                    BaseUtil.SetSessionValue(AdminInfo.UserID.ToString(), Convert.ToString(user.qenID));
                    //BaseUtil.SetSessionValue(AdminInfo.Mobile.ToString(), Convert.ToString(user.qenPhone));
                    BaseUtil.SetSessionValue(AdminInfo.role_id.ToString(), Convert.ToString(user.roleID));
                    BaseUtil.SetSessionValue(AdminInfo.FullName.ToString(), Convert.ToString(user.qenName));
                    ID = BaseUtil.GetSessionValue(AdminInfo.UserID.ToString());
                    BaseUtil.SetSessionValue(AdminInfo.logo.ToString(), Convert.ToString(user.qenImage));
                    BaseUtil.SetSessionValue(AdminInfo.mobileVerified.ToString(), Convert.ToString(user.isMobileVerified));
                    BaseUtil.SetSessionValue(AdminInfo.emailVerified.ToString(), Convert.ToString(user.isEmalVerified));
                    TempData["Success"] = "Linked";
                }

                return(RedirectToAction("jobs", "jobDetails", new { ID = ID }));
            }
            catch (Exception ex)
            {
                TempData["msg"] = ex.Message.ToString();
                BaseUtil.CaptureErrorValues(ex);
                return(RedirectToAction("Error"));
            }
        }