public ActionResult My_account(FormCollection collection) { if (!this.CheckMemberlogin()) { return(this.RedirectToAction("login", "account", new { return_url = string.Empty + Url.Action("my_account", "account") })); } else { var register_view = new Register_view(); this.TryUpdateModel(register_view); UserModels sv = new UserModels(); C_User it = new C_User(); C_UserInfo iit = new C_UserInfo(); register_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); register_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); if (HttpContext.Session["captchastring"] != null && register_view.Code == HttpContext.Session["captchastring"].ToString()) { bool infors = false; iit.FName = register_view.FirstName; iit.Email = register_view.Email; iit.Address = register_view.Address; if (!string.IsNullOrEmpty(register_view.Birthday)) { iit.Birthday = DateTime.Parse(register_view.Birthday); } iit.Phone = register_view.Phone; infors = sv.Add_User_Infor(iit); if (infors == true) { register_view.Message = App_GlobalResources.Lang.strMessageUpdateInforSuccess; } else { register_view.Message = App_GlobalResources.Lang.messErrorRegister; } } else { register_view.Message = App_GlobalResources.Lang.messCaptcha; } return(this.PartialView("../page/my_account", register_view)); } }
/// <summary> /// Instagrams the callback. /// </summary> /// <returns>the Instagram Call back</returns> public ActionResult InstagramCallback() { if (!string.IsNullOrEmpty(Request.QueryString["code"])) { string code = Request.QueryString["code"]; try { NameValueCollection parameters = new NameValueCollection(); parameters.Add("client_id", Util.GetConfigValue("AppInstagramID", string.Empty)); parameters.Add("client_secret", Util.GetConfigValue("AppInstagramSecret", string.Empty)); parameters.Add("grant_type", "authorization_code"); parameters.Add("redirect_uri", Util.GetConfigValue("AppIstagramReturn", string.Empty)); parameters.Add("code", code); WebClient client = new WebClient(); var result = client.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters); var response = System.Text.Encoding.Default.GetString(result); //// deserializing nested JSON string to object var javascriptResult = (JObject)JsonConvert.DeserializeObject(response); string accessToken = (string)javascriptResult["access_token"]; string id = (string)javascriptResult["user"]["id"]; string username_client = (string)javascriptResult["user"]["username"]; string fullname_client = (string)javascriptResult["user"]["full_name"]; ////This code register id and access token to get on client side ////Page.ClientScript.RegisterStartupScript(this.GetType(), "GetToken", "<script>var instagramaccessid=\"" + @"" + id + "" + "\"; var instagramaccesstoken=\"" + @"" + accessToken + "" + "\";</script>"); UserModels sv = new UserModels(); C_User it = new C_User(); C_UserInfo iit = new C_UserInfo(); it = sv.GetUserbyUserName(username_client); if (it == null) { it = new C_User(); string rt = string.Empty; bool infors = false; it.Username = username_client; it.Role = 2; it.Password = MD5Extend.EncodePassword("123456"); it.Online = true; it.IP = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString(); it.LastLogin = DateTime.Now; rt = sv.Add_User(it); iit.FName = fullname_client; iit.Email = username_client; ////iit.LName = middlename; iit.DateRegister = DateTime.Now; ////iit.EventId = string.IsNullOrEmpty(ids) != false ? int.Parse(ids) : 0; iit.Note = "Instagram login"; infors = sv.Add_User_Infor(iit); if (rt.Length > 0 && infors == true) { ////register_view.message = Lang.strMessageLogin; this.Session["acc"] = iit.FName; this.Session["mem"] = rt; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(iit.FName, rt, it.Role.ToString(), 6); } } else { iit = sv.GetUserInforByEmail(username_client); this.Session["acc"] = iit.FName; this.Session["mem"] = it.Username; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(iit.FName, it.Username, it.Role.ToString(), 6); it.Online = true; it.IP = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString(); it.LastLogin = DateTime.Now; sv.Update_User(it); } if (this.Session["Instagram_return"] != null && Url.IsLocalUrl(this.Session["Instagram_return"].ToString())) { return(this.Redirect(this.Session["Instagram_return"].ToString())); } else { return(this.RedirectToAction("index", "home")); } } catch (Exception) { throw; } } else { return(this.RedirectToAction("index", "home")); } }
/// <summary> /// Facebook the callback. /// </summary> /// <param name="code">The code.</param> /// <returns>Facebook Call back</returns> public ActionResult FacebookCallback(string code) { var fb = new Facebook.FacebookClient(); dynamic result = fb.Post("oauth/access_token", new { client_id = Util.GetConfigValue("AppFaceBookID", string.Empty), client_secret = Util.GetConfigValue("AppFacebookSecret", string.Empty), redirect_uri = this.RedirectUri.AbsoluteUri, code = code }); var accessToken = result.access_token; //// Store the access token in the session for farther use this.Session["AccessToken"] = accessToken; //// update the facebook client with the access token so //// we can make requests on behalf of the user fb.AccessToken = accessToken; //// Get the user's information dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email"); string email = me.email; string firstname = me.first_name; string middlename = me.middle_name; string lastname = me.last_name; string ids = me.id; //// Set the auth cookie ////FormsAuthentication.SetAuthCookie(email, false); UserModels sv = new UserModels(); C_User it = new C_User(); C_UserInfo iit = new C_UserInfo(); it = sv.GetUserbyUserName(email); if (it == null) { it = new C_User(); string rt = string.Empty; bool infors = false; it.Username = email; it.Role = 2; it.Password = MD5Extend.EncodePassword("123456"); it.Online = true; it.IP = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString(); it.LastLogin = DateTime.Now; rt = sv.Add_User(it); iit.FName = firstname; iit.Email = email; iit.LName = middlename; iit.DateRegister = DateTime.Now; iit.EventId = string.IsNullOrEmpty(ids) != false?int.Parse(ids) : 0; iit.Note = "Facebook login"; infors = sv.Add_User_Infor(iit); if (rt.Length > 0 && infors == true) { ////register_view.message = Lang.strMessageLogin; this.Session["acc"] = iit.FName; this.Session["mem"] = rt; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(iit.FName, rt, it.Role.ToString(), 6); } } else { iit = sv.GetUserInforByEmail(email); this.Session["acc"] = iit.FName; this.Session["mem"] = it.Username; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(iit.FName, it.Username, it.Role.ToString(), 6); it.Online = true; it.IP = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString(); it.LastLogin = DateTime.Now; sv.Update_User(it); } if (this.Session["FaceBook_return"] != null && Url.IsLocalUrl(this.Session["FaceBook_return"].ToString())) { return(this.Redirect(Session["FaceBook_return"].ToString())); } else { return(this.RedirectToAction("index", "home")); } }
/// <summary> /// Google the callback. /// </summary> /// <returns>Google Call back</returns> public ActionResult GoogleCallback() { GoogleConnect.ClientId = Util.GetConfigValue("AppGoogleID", string.Empty); GoogleConnect.ClientSecret = Util.GetConfigValue("AppGoogleSecret", string.Empty); if (!string.IsNullOrEmpty(Request.QueryString["code"])) { string code = Request.QueryString["code"]; string json = GoogleConnect.Fetch("me", code); GoogleProfile profile = new JavaScriptSerializer().Deserialize <GoogleProfile>(json); UserModels sv = new UserModels(); C_User it = new C_User(); C_UserInfo iit = new C_UserInfo(); it = sv.GetUserbyUserName(profile.Emails.Find(email => email.Type == "account").Value); if (it == null) { it = new C_User(); string rt = string.Empty; bool infors = false; it.Username = profile.Emails.Find(email => email.Type == "account").Value; it.Role = 2; it.Password = MD5Extend.EncodePassword("123456"); it.Online = true; it.IP = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString(); it.LastLogin = DateTime.Now; rt = sv.Add_User(it); iit.FName = profile.DisplayName; iit.Email = profile.Emails.Find(email => email.Type == "account").Value; ////iit.LName = middlename; iit.DateRegister = DateTime.Now; ////iit.EventId = string.IsNullOrEmpty(ids) != false ? int.Parse(ids) : 0; iit.Note = "Google login"; infors = sv.Add_User_Infor(iit); if (rt.Length > 0 && infors == true) { ////register_view.message = Lang.strMessageLogin; this.Session["acc"] = iit.FName; this.Session["mem"] = rt; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(iit.FName, rt, it.Role.ToString(), 6); } } else { iit = sv.GetUserInforByEmail(profile.Emails.Find(email => email.Type == "account").Value); this.Session["acc"] = iit.FName; this.Session["mem"] = it.Username; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(iit.FName, it.Username, it.Role.ToString(), 6); it.Online = true; it.IP = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString(); it.LastLogin = DateTime.Now; sv.Update_User(it); } ////lblId.Text = profile.Id; ////lblName.Text = profile.DisplayName; ////lblEmail.Text = profile.Emails.Find(email => email.Type == "account").Value; ////lblGender.Text = profile.Gender; ////lblType.Text = profile.ObjectType; ////ProfileImage.ImageUrl = profile.Image.Url; if (Request.QueryString["error"] == "access_denied") { ////login fail logger.Error("Error requesting OAuth user data from Google:" + Request.QueryString["error"]); } if (this.Session["Google_return"] != null && Url.IsLocalUrl(this.Session["Google_return"].ToString())) { return(this.Redirect(Session["Google_return"].ToString())); } else { return(this.RedirectToAction("index", "home")); } } else { return(this.RedirectToAction("index", "home")); } }
public ActionResult Register(FormCollection collection) { var register_view = new Register_view(); this.TryUpdateModel(register_view); UserModels sv = new UserModels(); C_User it = new C_User(); C_UserInfo iit = new C_UserInfo(); register_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); register_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); if (HttpContext.Session["captchastring"] != null && register_view.Code == HttpContext.Session["captchastring"].ToString()) { if (register_view.Password != register_view.Confirm_password) { register_view.Message = App_GlobalResources.Lang.messConfirmPassword; return(this.PartialView("../page/register", register_view)); } if (sv.GetUserbyUserName(register_view.Email) != null) { register_view.Message = App_GlobalResources.Lang.messExistsEmail; return(this.PartialView("../page/register", register_view)); } string rt = string.Empty; bool infors = false; it.Username = register_view.Email; it.Role = 2; it.Password = MD5Extend.EncodePassword(register_view.Password); it.IP = "not login"; it.Online = true; it.LastLogin = DateTime.Now; rt = sv.Add_User(it); iit.FName = register_view.FirstName; iit.Email = register_view.Email; infors = sv.Add_User_Infor(iit); if (rt.Length > 0 && infors == true) { register_view.Message = App_GlobalResources.Lang.strMessageLogin; this.Session["acc"] = register_view.Email; this.Session["mem"] = rt; this.Session["role"] = it.Role.ToString(); this.SetAccountCookies(register_view.Email, rt, it.Role.ToString(), 6); if (!string.IsNullOrEmpty(register_view.Return_url)) { return(this.Redirect(register_view.Return_url)); } else { return(this.RedirectToAction("index", "home")); } } else { register_view.Message = App_GlobalResources.Lang.messErrorRegister; return(this.PartialView("../page/register", register_view)); } } else { register_view.Message = App_GlobalResources.Lang.messCaptcha; return(this.PartialView("../page/register", register_view)); } }