protected void btn_login_Click(object sender, EventArgs e) { Model_Users u = UsersController.UserChecklogin(email_txt.Value.Trim(), password_txt.Value.Trim()); if (u != null) { UserSessionController.CloseOtherCurrentLogin(u.UserID); UserSessionController.SessionCreateUserFront(u); } else { Model_Users ux = UsersController.UserCheckloginExternal(email_txt.Value.Trim()); if (ux != null) { string url = Request.Url.ToString().Split('?')[0]; switch (ux.UserLoginChannel) { case UserLoginChannel.Application: Response.Redirect(url + "?loginfailed=passwordinvalid"); break; case UserLoginChannel.Facebook: Response.Redirect(url + "?loginfailed=sociallogin&s=facebook"); break; case UserLoginChannel.Google: Response.Redirect(url + "?loginfailed=sociallogin&s=google"); break; case UserLoginChannel.LinkedIn: Response.Redirect(url + "?loginfailed=sociallogin&s=linkedin"); break; } } else { } //FailureText.Text = "UserName Invalid"; //ErrorMessage.Visible = true; } }
protected void LogIn(object sender, EventArgs e) { Model_Users u = UsersController.AdminChecklogin(UserName.Text, Password.Text); if (u != null) { if (!u.Status) { HttpContext.Current.Response.Redirect("~/admin/accessdenie.aspx?error=noactivate"); } else { //StaffSessionAuthorize StaffSession = new StaffSessionAuthorize(); //StaffSession.CloseOtherCurrentLogin(clStaff.Staff_Id); UserSessionController.CloseOtherCurrentLogin(u.UserID); UserSessionController.SessionCreate(u); } } else { FailureText.Text = "UserName Invalid"; ErrorMessage.Visible = true; } //if (IsValid) //{ // // Validate the user password // //var manager = new UserManager(); // //ApplicationUser user = manager.Find(UserName.Text, Password.Text); // //if (user != null) // //{ // // IdentityHelper.SignIn(manager, user, RememberMe.Checked); // // IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); // //} // //else // //{ // // FailureText.Text = "Invalid username or password."; // // ErrorMessage.Visible = true; // //} //} }
//public Microsoft.Owin.IOwinContext Context { get; set; } public void Page_Load(object sender, EventArgs e) { string client_id = "81h1zat2gc50un"; string client_secret = "ZLi6H1m1k6EICMES"; string code = Request.QueryString["code"]; string redirect = Request.Url.AbsoluteUri.Split('?')[0].Replace("http", "https"); string URI = "https://www.linkedin.com/uas/oauth2/accessToken"; // string URI = "http://www.myurl.com/post.php"; string myParameters = "grant_type=authorization_code&client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code + "&redirect_uri=" + redirect; //Response.Write(URI + "?" + myParameters); //Response.End(); string HtmlResult = string.Empty; using (WebClient wc = new WebClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; HtmlResult = wc.UploadString(URI, myParameters); } var jsonHtmlResult = JsonHelper.JsonTODynamic(HtmlResult); string urlprofile = "https://api.linkedin.com/v1/people/~:(id,formatted-name,first-name,last-name,email-address,picture-url,picture-urls::(original),headline,public-profile-url,positions)"; string param = "oauth2_access_token=" + jsonHtmlResult["access_token"] + "&format=json"; string userdata = string.Empty; //using (WebClient wc = new WebClient()) //{ // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; // userdata = wc.UploadString(urlprofile, param); //} string urlcom = urlprofile + "?" + param; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(urlcom); request.Method = "GET"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); userdata = reader.ReadToEnd(); reader.Close(); dataStream.Close(); } var UserJson = JsonHelper.JsonTODynamic(userdata); //firstName // lastName emailAddress pictureUrl string firstName = UserJson["firstName"]; string lastName = UserJson["lastName"]; string emailAddress = UserJson["emailAddress"]; string pictureUrl = UserJson["pictureUrl"]; Model_Users u = UsersController.UserCheckloginExternal(emailAddress.Trim()); if (u != null) { if (string.IsNullOrEmpty(u.PicturePath)) { u.PicturePath = pictureUrl; u.UpdateUserProfilePicutre(u); } UserSessionController.CloseOtherCurrentLogin(u.UserID); UserSessionController.SessionCreateUserFront(u); } else { Model_Users mu = new Model_Users { Email = emailAddress.Trim(), UserName = emailAddress.Trim(), Gender = 3, Password = DateTime.Now.ToString("ddmmyyyyhhmmss"), UserCatId = 1, UserLoginChannel = UserLoginChannel.Facebook, FirstName = firstName, LastName = lastName, EmailVerify = false, PicturePath = pictureUrl }; int ret = UsersController.InsertUserExternal(mu); if (ret > 0) { Model_Users cmu = UsersController.GetUserbyID(ret); UserSessionController.CloseOtherCurrentLogin(cmu.UserID); UserSessionController.SessionCreateUserFront(cmu); } else { //RadioButton ra =(RadioButton)this.Page.FindControl("tab-2"); //ra.Checked = true; //emailerror.EnableClientScript = false; //emailerror.ErrorMessage = "the Email has already use"; //ClientScript.RegisterClientScriptBlock(typeof(Page), "myscript", "checkpan()", true); // alert.Text = "the Email has already use"; } } //LinkedInConnect.APIKey = "81h1zat2gc50un"; //LinkedInConnect.APISecret = "ZLi6H1m1k6EICMES"; //LinkedInConnect.RedirectUrl = Request.Url.AbsoluteUri.Split('?')[0]; //if (LinkedInConnect.IsAuthorized) //{ // string ff = (string)Session["access_token"]; // pnlDetails.Visible = true; // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // DataSet ds = LinkedInConnect.Fetch(); // string json = ds.ObjectToJSON(); // Response.Write(json); // Response.End(); // imgPicture.ImageUrl = ds.Tables["person"].Rows[0]["picture-url"].ToString(); // lblName.Text = ds.Tables["person"].Rows[0]["first-name"].ToString(); // lblName.Text += " " + ds.Tables["person"].Rows[0]["last-name"].ToString(); // lblEmailAddress.Text = ds.Tables["person"].Rows[0]["email-address"].ToString(); // lblHeadline.Text = ds.Tables["person"].Rows[0]["headline"].ToString(); // lblIndustry.Text = ds.Tables["person"].Rows[0]["industry"].ToString(); // lblLinkedInId.Text = ds.Tables["person"].Rows[0]["id"].ToString(); // lblLocation.Text = ds.Tables["location"].Rows[0]["name"].ToString(); // imgPicture.ImageUrl = ds.Tables["person"].Rows[0]["picture-url"].ToString(); //} }
//private static string GetFacebookUserJSON(string access_token) //{ // string url = string.Format("https://graph.facebook.com/me?access_token={0}&fields=email,name,first_name,last_name,link", access_token); // WebClient wc = new WebClient(); // Stream data = wc.OpenRead(url); // StreamReader reader = new StreamReader(data); // string s = reader.ReadToEnd(); // data.Close(); // reader.Close(); // return s; //} protected void btnSignup_Click(object sender, EventArgs e) { DateTime dBirth = new DateTime(int.Parse(useryear.Value), int.Parse(usermonth.Value), int.Parse(userday.Value)); Model_Users mu = new Model_Users { Email = signup_email.Value.Trim(), UserName = signup_email.Value.Trim(), Password = userpassword.Value.Trim(), UserCatId = 1, UserLoginChannel = UserLoginChannel.Application, ContryCode = country_code.Value.Trim(), AreaLocation = area_location.Value.Trim(), AreaLocation2 = area_location2.Value.Trim(), Gender = byte.Parse(usergender.Value), DateofBirth = dBirth, MobileNumber = userphone.Value.Trim() }; int ret = UsersController.InsertUser(mu); if (ret > 0) { Model_Users cmu = UsersController.GetUserbyID(ret); UserSessionController.CloseOtherCurrentLogin(cmu.UserID); UserSessionController.SessionCreateUserFront(cmu); } else { if (ret < 0) { //case already registered; Model_Users ux = UsersController.UserCheckloginExternal(signup_email.Value.Trim()); if (ux != null) { string url = Request.Url.ToString().Split('?')[0]; switch (ux.UserLoginChannel) { case UserLoginChannel.Application: Response.Redirect(url + "?loginfailed=already"); break; case UserLoginChannel.Facebook: Response.Redirect(url + "?loginfailed=sociallogin&s=facebook"); break; case UserLoginChannel.Google: Response.Redirect(url + "?loginfailed=sociallogin&s=google"); break; case UserLoginChannel.LinkedIn: Response.Redirect(url + "?loginfailed=sociallogin&s=linkedin"); break; } } } //RadioButton ra =(RadioButton)this.Page.FindControl("tab-2"); //ra.Checked = true; //emailerror.EnableClientScript = false; //emailerror.ErrorMessage = "the Email has already use"; //ClientScript.RegisterClientScriptBlock(typeof(Page), "myscript", "checkpan()", true); // alert.Text = "the Email has already use"; } }
protected void Page_Load(object sender, EventArgs e) { if (string.IsNullOrEmpty(Request.QueryString["access_token"])) { return; //ERROR! No token returned from Facebook!! } //let's send an http-request to facebook using the token string json = GetFacebookUserJSON(Request.QueryString["access_token"]); //and Deserialize the JSON response JavaScriptSerializer js = new JavaScriptSerializer(); FacebookUser oUser = js.Deserialize <FacebookUser>(json); if (oUser != null) { //Response.Write("Welcome, " + oUser.name); //// Response.Write("<br />id, " + oUser.id); //Response.Write("<br />Email : " + oUser.email); //Response.Write("<br />First_name: " + oUser.first_name); //Response.Write("<br />Last_name: " + oUser.last_name); //Response.Write("<br />Gender: " + oUser.gender); //Response.Write("<br />Link: " + oUser.link); //checkuser facebook channel string sex = oUser.gender; string userID = oUser.id.ToString(); // http://graph.facebook.com/10159605614725366/picture?type=large string strPicturePath = "http://graph.facebook.com/" + userID + "/picture?type=large"; Model_Users u = UsersController.UserCheckloginExternal(oUser.email.Trim()); if (u != null) { if (string.IsNullOrEmpty(u.PicturePath)) { u.PicturePath = strPicturePath; u.UpdateUserProfilePicutre(u); } UserSessionController.CloseOtherCurrentLogin(u.UserID); UserSessionController.SessionCreateUserFront(u); } else { Model_Users mu = new Model_Users { Email = oUser.email, UserName = oUser.email, Gender = (byte)(oUser.gender == "male" ? 1 : 2), Password = DateTime.Now.ToString("ddmmyyyyhhmmss"), UserCatId = 1, UserLoginChannel = UserLoginChannel.Facebook, FirstName = oUser.first_name, LastName = oUser.last_name, EmailVerify = false, PicturePath = strPicturePath }; int ret = UsersController.InsertUserExternal(mu); if (ret > 0) { Model_Users cmu = UsersController.GetUserbyID(ret); UserSessionController.CloseOtherCurrentLogin(cmu.UserID); UserSessionController.SessionCreateUserFront(cmu); } else { //RadioButton ra =(RadioButton)this.Page.FindControl("tab-2"); //ra.Checked = true; //emailerror.EnableClientScript = false; //emailerror.ErrorMessage = "the Email has already use"; //ClientScript.RegisterClientScriptBlock(typeof(Page), "myscript", "checkpan()", true); // alert.Text = "the Email has already use"; } } } }