public ActionResult updateBeforeLoginUserProjectDetailsService() { var SignalRHub = new SignalRHub(); string totalProjects = "152"; string successRate = "94.2"; string totalUsers = "3854"; string projectCategories = "37"; var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate,totalUsers,projectCategories); //sendMessage //SignalRHub.updateBeforeLoginUserProjectDetails(totalProjects, successRate,totalUsers,projectCategories); return Json("success", JsonRequestBehavior.AllowGet); }
public ResponseModel<String> WebRegisterService(RegisterationRequest req, HttpRequestBase request) { var response = new ResponseModel<String>(); if (_db.Users.Any(x => x.Username == req.Username)) { response.Status = 409; response.Message = "conflict"; return response; } var guid = Guid.NewGuid().ToString(); var user = new User { Username = req.Username, Password = EncryptionClass.Md5Hash(req.Password), Source = req.Source, isActive = "false", Type = req.Type, guid = Guid.NewGuid().ToString(), fixedGuid= Guid.NewGuid().ToString(), FirstName = req.FirstName, LastName = req.LastName, gender = "NA", ImageUrl = "NA" }; _db.Users.Add(user); if (!Constants.NA.Equals(req.Referral)) { new ReferralService().payReferralBonusAsync(req.Referral, req.Username,Constants.status_false); } if (req.Type == "client") { var dbClientDetails = new ClientDetail { Username = req.Username, CompanyName = string.IsNullOrEmpty(req.CompanyName)?"NA":req.CompanyName }; _db.ClientDetails.Add(dbClientDetails); } var dbValidateUserKey = new ValidateUserKey { Username = req.Username, guid = guid }; _db.ValidateUserKeys.Add(dbValidateUserKey); try { _db.SaveChanges(); var signalRHub = new SignalRHub(); string totalProjects = ""; string successRate = ""; string totalUsers = _db.Users.Count().ToString(CultureInfo.InvariantCulture); string projectCategories = ""; var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories); SendAccountCreationValidationEmail.SendAccountCreationValidationEmailMessage(req.Username, guid, request); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!!"; return response; } response.Status = 200; response.Message = "success"; response.Payload = "Account Created"; return response; }
public ResponseModel<string> CreateTemplate(List<CreateTemplateQuestionInfoModel> req,string username,TemplateInfoModel TemplateInfo) { var response = new ResponseModel<string>(); var keyInfo = _db.CreateTemplateQuestionInfoes.FirstOrDefault(); var refKey = _db.Users.SingleOrDefault(x=>x.Username == username).guid; var digitKey = 0; Random rnd = new Random(); int randomValue = rnd.Next(1, 10000); if (keyInfo != null) { digitKey = _db.CreateTemplateQuestionInfoes.Max(x => x.Id) + 1; } else { digitKey = 1; } refKey += digitKey + randomValue; if (TemplateInfo.type == Constants.type_Ads && TemplateInfo.subType == Constants.subType_facebookLike) { var facebookFindPageId = TemplateInfo.pageId.Split('/'); var createTemplateFacebookLikeInsert = new CreateTemplateFacebookLike { username = username, title = req[0].title, type = TemplateInfo.type, subType = TemplateInfo.subType, creationTime = DateTime.Now.ToString(CultureInfo.InvariantCulture), referenceId = refKey, totalThreads = TemplateInfo.totalThreads, completed = Constants.NA, verified = Constants.NA, payPerUser = TemplateInfo.amountEachThread, DateTime = DateTime.Now, description = (req[3].textBoxQuestionsList[0].Question) == null ? Constants.NA : req[3].textBoxQuestionsList[0].Question, pageId = facebookFindPageId[facebookFindPageId.Length-1], pageUrl = TemplateInfo.pageUrl }; _db.CreateTemplateFacebookLikes.Add(createTemplateFacebookLikeInsert); try { _db.SaveChanges(); var signalRHub = new SignalRHub(); string totalProjects = new ProjectDAO().totalAvailableProjects(); string successRate = ""; string totalUsers = ""; string projectCategories = ""; var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories); response.Status = 200; response.Message = "success-" + digitKey; response.Payload = refKey; } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Failed"; response.Payload = "Exception Occured"; } } else { var createTemplateQuestionsInfoInsert = new CreateTemplateQuestionInfo { description = TemplateInfo.description != null ? TemplateInfo.description : Constants.NA, username = username, title = req[0].title, visible = Constants.NA, type = TemplateInfo.type, subType = TemplateInfo.subType, creationTime = DateTime.Now.ToString(CultureInfo.InvariantCulture), referenceId = refKey, totalThreads = TemplateInfo.totalThreads, completed = Constants.NA, verified = Constants.NA, payPerUser = TemplateInfo.amountEachThread }; _db.CreateTemplateQuestionInfoes.Add(createTemplateQuestionsInfoInsert); try { _db.SaveChanges(); CreateSubTemplateByRefKey CreateSubTemplateByRefKey = new CreateSubTemplateByRefKey(); CreateSubTemplateByRefKey.CreateSubTemplateByRefKeyService(req, username, refKey); var signalRHub = new SignalRHub(); string totalProjects = new ProjectDAO().totalAvailableProjects(); string successRate = ""; string totalUsers = ""; string projectCategories = ""; var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>(); hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories); new SendNewTaskService().SendUserTaskNotificationToAllAsync(createTemplateQuestionsInfoInsert.title, "Total " + createTemplateQuestionsInfoInsert.totalThreads+" available",DateTime.Now); response.Status = 200; response.Message = "success-" + digitKey; response.Payload = refKey; } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Failed"; response.Payload = "Exception Occured"; } } return response; }
public ResponseModel<LoginResponse> CheckAndSaveFacebookUserInfoIntoDatabase(string fid, string refKey, string access_token, bool isMobileApiCall) { var response = new ResponseModel<LoginResponse>(); var ifFacebookUserAlreadyRegistered = _db.FacebookAuths.SingleOrDefault(x => x.facebookId == fid); if (isMobileApiCall) { var fb = new FacebookClient(access_token); dynamic fqlResponse = fb.Get("fql", new { q = "SELECT uid, first_name, last_name, sex, pic_big_with_logo, username FROM user WHERE uid=me()" }); var FacebookAuthData = new FacebookAuth(); FacebookAuthData.username = Constants.NA; FacebookAuthData.AuthToken = access_token; FacebookAuthData.datetime = DateTime.Now.ToString(); FacebookAuthData.facebookId = Convert.ToString(fqlResponse.data[0].uid); FacebookAuthData.facebookUsername = fqlResponse.data[0].username; //var ifAlreadyExists = _db.FacebookAuths.SingleOrDefault(x => x.facebookId == fid); if (ifFacebookUserAlreadyRegistered == null) { _db.FacebookAuths.Add(FacebookAuthData); ifFacebookUserAlreadyRegistered = FacebookAuthData; } else { // refresh the token ifFacebookUserAlreadyRegistered.AuthToken = access_token; ifFacebookUserAlreadyRegistered.datetime = DateTime.Now.ToString(); } } //var ifFacebookUserAlreadyRegistered = _db.FacebookAuths.SingleOrDefault(x => x.facebookId == fid); if (ifFacebookUserAlreadyRegistered.username != Constants.NA) { if (_db.Users.Any(x => x.Username == ifFacebookUserAlreadyRegistered.username)) { var user = _db.Users.SingleOrDefault(x => x.Username == ifFacebookUserAlreadyRegistered.username); if (user != null) { 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 facebook"; try { user.KeepMeSignedIn = "true";//keepMeSignedIn.Equals("true", StringComparison.OrdinalIgnoreCase) ? "true" : "false"; user.Locked = Constants.status_false; _db.SaveChanges(); var session = new M2ESession(ifFacebookUserAlreadyRegistered.username); TokenManager.CreateSession(session); response.Payload.UTMZT = session.SessionId; return response; } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Payload.Code = "500"; return response; } } else response.Payload.Code = "403"; } } else { //save user details in database .. var fb = new FacebookClient(ifFacebookUserAlreadyRegistered.AuthToken); dynamic result = fb.Get("fql", new { q = "SELECT uid, first_name, last_name, sex, pic_big_with_logo, username FROM user WHERE uid=me()" }); var guid = Guid.NewGuid().ToString(); var user = new User { Username = result.data[0].username + "@facebook.com", Password = EncryptionClass.Md5Hash(Guid.NewGuid().ToString()), Source = "facebook", isActive = "true", Type = "user", guid = Guid.NewGuid().ToString(), fixedGuid = Guid.NewGuid().ToString(), FirstName = result.data[0].first_name, LastName = result.data[0].last_name, gender = result.data[0].sex, ImageUrl = result.data[0].pic_big_with_logo }; _db.Users.Add(user); if (!Constants.NA.Equals(refKey)) { new ReferralService().payReferralBonusAsync(refKey, user.Username, Constants.status_true); } try { ifFacebookUserAlreadyRegistered.username = user.Username; _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 facebook"; try { var session = new M2ESession(ifFacebookUserAlreadyRegistered.username); TokenManager.CreateSession(session); response.Payload.UTMZT = session.SessionId; } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!"; } 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); } catch (DbEntityValidationException e) { DbContextException.LogDbContextException(e); response.Status = 500; response.Message = "Internal Server Error !!!"; } } return response; }
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 ActionResult GoogleLogin(string type) { var response = new ResponseModel<LoginResponse>(); String code = Request.QueryString["code"]; String refKey = Request.QueryString["refKey"]; string app_id = ""; string app_secret = ""; if (Request.Url.Authority.Contains("localhost")) { app_id = ConfigurationManager.AppSettings["googleAppID"].ToString(); app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString(); } else { app_id = ConfigurationManager.AppSettings["googleAppIDCautom"].ToString(); app_secret = ConfigurationManager.AppSettings["googleAppSecretCautom"].ToString(); } string scope = "email%20profile"; string returnUrl = "http://" + Request.Url.Authority + "/SocialAuth/GoogleLogin"; if (code == null) { var 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)); Response.Redirect(ReturnUrl); } 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; 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)); var ifUserAlreadyRegistered = _db.Users.SingleOrDefault(x => x.Username == googleUserDetails.email); 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 google"; 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; ViewBag.isNewUser = "******"; 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 (googleUserDetails.picture == null || googleUserDetails.picture == "") googleUserDetails.picture = Constants.NA; // if picture is not available. if (googleUserDetails.gender == null || googleUserDetails.gender == "") googleUserDetails.gender = Constants.NA; // if picture is not available. var user = new User { Username = googleUserDetails.email, Password = EncryptionClass.Md5Hash(Guid.NewGuid().ToString()), Source = "google", isActive = "true", Type = "user", guid = Guid.NewGuid().ToString(), fixedGuid = Guid.NewGuid().ToString(), FirstName = googleUserDetails.given_name, LastName = googleUserDetails.family_name, gender = googleUserDetails.gender, ImageUrl = googleUserDetails.picture }; _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 google"; 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 !!!"; } } } return Json(response,JsonRequestBehavior.AllowGet); }