public LogOnModel webLogin(string userName, string passwrod, string returnUrl, string keepMeSignedIn) { var model = new LogOnModel(); webLoginService webLoginService = new webLoginService(); model = webLoginService.Login(userName, passwrod, returnUrl, keepMeSignedIn); return model; }
public LogOnModel linkedinLogin(string returnUrl, string AbsoluteUri, string oauth_token, string oauth_verifier, string referral, string userType) { var model = new LogOnModel(); linkedinService linkedinService = new linkedinService(); model = linkedinService.Login(returnUrl, AbsoluteUri, oauth_token, oauth_verifier, referral, userType); return model; }
public LogOnModel twitterinLogin(string returnUrl, string AbsoluteUri, string oauth_token, string oauth_verifier) { var model = new LogOnModel(); twitterService twitterService = new twitterService(); model = twitterService.Login(returnUrl, AbsoluteUri, oauth_token, oauth_verifier); return model; }
public LogOnModel Login(string returnUrl, string AbsoluteUri, string oauth_token, string oauth_verifier) { var userData = new LogOnModel(); twitterService twitterService = new Service.twitterService(); twitterService.loginInit(oauth_token, oauth_verifier); return userData; }
public LogOnModel googleLogin(string returnUrl, string code, string referral,string userType) { var model = new LogOnModel(); googleService googleService = new googleService(); model = googleService.Login(returnUrl, code, referral, userType); return model; }
public LogOnModel facebookLogin(string returnUrl, string code, string referral,string userType) { var model = new LogOnModel(); FacebookService FacebookService = new FacebookService(); model = FacebookService.Login(returnUrl, code, referral, userType); return model; }
public LogOnModel LogOn(string returnUrl) { var model = new LogOnModel(); if (!String.IsNullOrEmpty(returnUrl)) model.ReturnUrl = returnUrl; else model.ReturnUrl = "/"; //check if user is authenticated.. //model.User return model; }
public LogOnModel Login(string userName, string passwrod, string returnUrl, string keepMeSignedIn) { var _db = new ZestorkContainer(); var userData = new LogOnModel(); if (_db.Users.Any(x => x.Username == userName && x.Password == passwrod)) { Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive=="true"); if (user != null) { userData.User = new User(); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.User.Email = user.Username; try { if (keepMeSignedIn == "true") user.KeepMeSignedIn = "true"; else user.KeepMeSignedIn = "false"; _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); } userData.User.keepMeSignedIn = user.KeepMeSignedIn; userData.statusCode = "200"; } else userData.statusCode = "403"; } else userData.statusCode = "401"; userData.ReturnUrl = returnUrl; return userData; }
public LogOnModel Login(string returnUrl, string AbsoluteUri, string oauth_token, string oauth_verifier, string referral,string userType) { var userData = new LogOnModel(); var _db = new ZestorkContainer(); string authLink = string.Empty; if (oauth_token != null && oauth_verifier != null) { var linkedInApiDataResponse = _db.LinkedInAuthApiDatas.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 UserDetails = JsonConvert.DeserializeObject<linkedinUserDataWrapper>(Convert.ToString(UserDetailString)); _db.LinkedInAuthApiDatas.Attach(linkedInApiDataResponse); _db.LinkedInAuthApiDatas.Remove(linkedInApiDataResponse); //_db.SaveChanges(); userData.User = new User(); if (_db.Users.Any(x => x.Username == UserDetails.emailAddress)) { Users user = _db.Users.SingleOrDefault(x => x.Username == UserDetails.emailAddress); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.statusCode = "200"; } else { // add user in database String ID = Guid.NewGuid().ToString(); userData.User.FirstName = UserDetails.firstName; userData.User.LastName = UserDetails.lastName; userData.User.Username = UserDetails.emailAddress; try { userData.User.Email = UserDetails.emailAddress; } catch (Exception) { userData.User.Email = "NA"; } userData.User.Gender = "NA"; userData.User.ImageUrl = "NA"; userData.User.Username = UserDetails.emailAddress; var user = new Users { Username = UserDetails.emailAddress, Password = Guid.NewGuid().ToString(), Source = "linkedin", isActive = "true", Type = userType != null ? userType : "NA", guid = Guid.NewGuid().ToString(), FirstName = UserDetails.firstName, LastName = UserDetails.lastName, gender = "NA", ImageUrl = "NA" }; _db.Users.Add(user); try { _db.SaveChanges(); userData.statusCode = "200"; } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } } } } else { authLink = CreateAuthorization(); var linkedInApiData = new LinkedInAuthApiData { oauth_Token = _oauth.Token, oauth_TokenSecret = _oauth.TokenSecret, oauth_verifier = "" }; _db.LinkedInAuthApiDatas.Add(linkedInApiData); try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } userData.ReturnUrl = authLink; } return userData; }
public LogOnModel Login(string returnUrl) { var model = new LogOnModel(); return model; }
public JsonResult Login(string id) { //ServicePointManager.ServerCertificateValidationCallback = delegate //{ return true; }; String returnUrl = ""; String userType = string.Empty; String referral = Request.QueryString["ref"]; var userData = new LogOnModel(); LoginService LoginService = new LoginService(); if (id == "facebook") { String code = Request.QueryString["code"]; if (code == null) Session["userType"] = Request.QueryString["userType"]; else { userType = Session["userType"].ToString(); Session.Remove("userType"); } userData = LoginService.facebookLogin("http://" + Request.Url.Authority + "/Account/Login/facebook/", code, referral, userType); } else if (id == "web") { String userName = Request.Form["userName"]; String password = Request.Form["password"]; String keepMeSignedIn = Request.Form["keepMeSignedInCheckBox"]; if (keepMeSignedIn != null) keepMeSignedIn = "true"; else keepMeSignedIn = "false"; userData = LoginService.webLogin(userName, password, returnUrl, keepMeSignedIn); } else if (id == "google") { if (Request.QueryString["access_token"] != null) { string access_token = Request.QueryString["access_token"]; } String code = Request.QueryString["code"]; if (code == null) Session["userType"] = Request.QueryString["userType"]; else { userType = Session["userType"].ToString(); Session.Remove("userType"); } userData = LoginService.googleLogin("http://" + Request.Url.Authority + "/Account/Login/google", code, referral,userType); } else if (id == "linkedin") { String AbsoluteUri = Request.Url.AbsoluteUri; string oauth_token = Request.QueryString["oauth_token"]; string oauth_verifier = Request.QueryString["oauth_verifier"]; if (oauth_token != null && oauth_verifier != null) { Session["userType"] = Request.QueryString["userType"]; } else { userType = Session["userType"].ToString(); Session.Remove("userType"); } userData = LoginService.linkedinLogin("http://" + Request.Url.Authority + "/Account/Login/linkedin", AbsoluteUri, oauth_token, oauth_verifier, referral, userType); } else if (id == "twitter") { String AbsoluteUri = Request.Url.AbsoluteUri; string oauth_token = Request.QueryString["oauth_token"]; string oauth_verifier = Request.QueryString["oauth_verifier"]; userData = LoginService.twitterinLogin("http://" + Request.Url.Authority + "/Account/Login/twitter", AbsoluteUri, oauth_token, oauth_verifier); } //check for specific status code if (userData.statusCode != null) { if (userData.statusCode != "200") { Response.Redirect("/#/login/" + userData.statusCode); } else { #region Session CPSession session = new CPSession(); session.addAttribute("userName", userData.User.Username); session.addAttribute("type", AccountControllerMethods.getUserType(userData.User.Username)); bool isPersistent = false; // as of now we have only 1 type of login TokenManager.CreateSession(session, isPersistent); userData.User.guid = session.getID(); #endregion if (userData.User.ImageUrl == "NA") userData.User.ImageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; Response.Redirect("/Account/welcome?guid=" + userData.User.guid + "&username="******"&keepMeSignedIn=" + userData.User.keepMeSignedIn + "&type=" + session.getAttributeValue("type") + "&pass=true/#/"); //return View("Index", "User" , userData); //HttpContext.Response.AppendHeader("Authorization", userData.User.guid); } } return Json(userData, JsonRequestBehavior.AllowGet); }
public LogOnModel Login(string returnUrl, string code, string referral,string userType) { var _db = new ZestorkContainer(); var userData = new LogOnModel(); string app_id = ""; string app_secret = ""; app_id = ConfigurationManager.AppSettings["googleAppID"].ToString(); app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString(); //if (returnUrl.Contains("zestork.pcongo")) //{ // app_id = ConfigurationManager.AppSettings["googleAppIDZestork"].ToString(); // app_secret = ConfigurationManager.AppSettings["googleAppSecretZestork"].ToString(); //} //else //{ // app_id = ConfigurationManager.AppSettings["googleAppID"].ToString(); // app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString(); //} string scope = "email%20profile"; if (code == null) { userData.ReturnUrl = (string.Format( "https://accounts.google.com/o/oauth2/auth?scope={0}&state=%2Fprofile&redirect_uri={1}&response_type=code&client_id={2}&approval_prompt=force", scope, returnUrl, app_id)); logger.Info(userData.ReturnUrl); return userData; } else { string access_token = getGoogleAuthToken(returnUrl, scope, code, app_id, app_secret); String URI = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + access_token; logger.Info(URI); WebClient webClient = new WebClient(); Stream stream = webClient.OpenRead(URI); string googleUserDetailString; /*I have not used any JSON parser because I do not want to use any extra dll/3rd party dll*/ using (StreamReader br = new StreamReader(stream)) { googleUserDetailString = br.ReadToEnd(); } var googleUserDetails = JsonConvert.DeserializeObject<googleUserDetails>(Convert.ToString(googleUserDetailString)); userData.User = new User(); if (_db.Users.Any(x => x.Username == googleUserDetails.email)) { Users user = _db.Users.SingleOrDefault(x => x.Username == googleUserDetails.email); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.statusCode = "200"; } else { // add user in database String ID = Guid.NewGuid().ToString(); userData.User.FirstName = googleUserDetails.given_name; userData.User.LastName = googleUserDetails.family_name; try { userData.User.Username = googleUserDetails.email; userData.User.Email = googleUserDetails.email; } catch (Exception) { userData.User.Username = "******"; userData.User.Email = "NA"; } try { userData.User.Gender = googleUserDetails.gender; } catch (Exception) { userData.User.Gender = "NA"; throw; } try { userData.User.ImageUrl = googleUserDetails.picture; } catch (Exception) { userData.User.ImageUrl = "NA"; } if (userData.User.Gender == null) userData.User.Gender = "NA"; logger.Info(JsonConvert.SerializeObject(userData)); var user = new Users { Username = userData.User.Email, Password = Guid.NewGuid().ToString(), Source = "google", isActive = "true", Type = userType != null ? userType : "NA", guid = Guid.NewGuid().ToString(), FirstName = userData.User.FirstName, LastName = userData.User.LastName, gender = userData.User.Gender, ImageUrl = userData.User.ImageUrl, }; _db.Users.Add(user); try { _db.SaveChanges(); userData.statusCode = "200"; } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } } } return userData; }
private LogOnModel checkFacebookAuthorization(string returnUrl, string code, string userType) { var userData = new LogOnModel(); try { var _db = new ZestorkContainer(); string app_id = string.Empty; string app_secret = string.Empty; app_id = ConfigurationManager.AppSettings["FacebookAppID"].ToString(); app_secret = ConfigurationManager.AppSettings["FacebookAppSecret"].ToString(); string scope = ""; if (code == null) { userData.ReturnUrl = (string.Format( "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, returnUrl, scope)); return userData; } else { string access_token = getFacebookAuthToken(returnUrl, scope, code,app_id,app_secret); var client = new FacebookClient(access_token); dynamic me = client.Get("me"); String userName = Convert.ToString(me.username); userData.User = new User(); if (_db.Users.Any(x => x.Username == userName + "@facebook.com")) { Users user = _db.Users.SingleOrDefault(x => x.Username == userName + "@facebook.com"); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.statusCode = "200"; } else { // add user in database String ID = Guid.NewGuid().ToString(); String ImageUrl = FacebookService.GetPictureUrl(userName); userData.User.FirstName = me.first_name; userData.User.LastName = me.last_name; userData.User.Username = me.username; userData.User.ImageUrl = ImageUrl; userData.User.Username = userName + "@facebook.com"; var user = new Users { Username = userName + "@facebook.com", Password = Guid.NewGuid().ToString(), Source = "facebook", isActive = "true", Type = userType!=null?userType:"NA", guid = Guid.NewGuid().ToString(), FirstName = me.first_name, LastName = me.last_name, gender = "NA", ImageUrl = ImageUrl }; _db.Users.Add(user); try { _db.SaveChanges(); userData.statusCode = "200"; } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } } } } catch (Exception ex) { logger.Error("facebook login error", ex); throw; } return userData; }
public LogOnModel Login(string returnUrl, string code, string referral,string userType) { var userData = new LogOnModel(); userData = checkFacebookAuthorization(returnUrl, code, userType); return userData; }