/// <summary> /// Logs a member and returns authentication token /// </summary> /// <param name="apiMember"></param> /// <param name="member"></param> /// <returns></returns> /// public Authentication GetAuthenticatedMemberLoginToken(ApiAccess apiMember, Member member) { Authentication auth = null; try { if (null == member || !member.IsActive) { return GetBadAuthentication("Member not found or is inactive"); } const string hoursAhead = "1000"; var sessionEnds = DateTime.Now.AddHours(Convert.ToDouble(hoursAhead)).Ticks; var plainAuthKey = String.Concat(Convert.ToString(member.MemberId), doubleUC, Convert.ToString(sessionEnds), doubleUC, apiMember.AppKey); var generatedAuthKey = plainAuthKey.EncryptSymmetric<RijndaelManaged>(encryptPass, encryptSalt); auth = new Authentication { Reason = String.Empty, Success = true, AuthKey = generatedAuthKey }; } catch (Exception e) { auth = GetBadAuthentication("Invalid facebook key and/or member not found"); } return auth; }
public ActionResult RegisterFacebookMember(string appKey, string facebookKey, string firstName, string lastName, string email, string deviceId, string mobilePhoneNumber = null, string phoneModel = "iPhone") { var apiAccessRepo = new ApiAccessRepository(); var apiAccess = apiAccessRepo.GetMemberByPublicApiKey(appKey); var apiAuthResult = new ApiAuthResult(); if (null != apiAccess) { try { var memberRepo = new MemberRepository(); var now = DateTime.Now; var member = memberRepo.GetByFacebookKey(facebookKey); if (null == member) { member = new Member(); member.FirstName = firstName; member.LastName = lastName; member.Email = email; member.FacebookId = facebookKey; member.DateCreated = now; member.MemberTypeId = 1; } member.DateUpdated = now; member.DateLastAccessed = now; memberRepo.Save(member); //Now Get User Auth Token var authService = new AuthenticationService(); var auth = authService.GetAuthenticatedMemberLoginToken(apiAccess, member); apiAuthResult.Success = auth.Success; apiAuthResult.Description = auth.Reason; apiAuthResult.AuthKey = auth.AuthKey; }catch(Exception e) { apiAuthResult.Success = false; apiAuthResult.Description = "Failed to save member and/or generate auth token"; apiAuthResult.AuthKey = ""; } }else { apiAuthResult.Success = false; apiAuthResult.Description = "Invalid AppKey"; apiAuthResult.AuthKey = ""; } return this.ToXml(apiAuthResult); }
public static void SendSmsLoginResponse(Member member) { // set our AccountSid and AuthToken var AccountSid = "AC8bc41784ae75963713052f18956296bd"; var AuthToken = "da0459307590d485c0e810b49f951de0"; var fromNumber = "646-783-2676"; // instantiate a new Twilio Rest Client var client = new TwilioRestClient(AccountSid, AuthToken); // make an associative array of people we know, indexed by phone number String[] peopleToReceiveSms = { "310-489-0841", "310-658-9646" }; // // iterate over all our friends foreach (var toNumber in peopleToReceiveSms) { // Send a new outgoing SMS by POSTing to the SMS resource */ client.SendSmsMessage( fromNumber, // From number, must be an SMS-enabled Twilio number toNumber, // To number, if using Sandbox see note above // message content String.Format("Banana Split has setup your account successfully {0} {1}", member.FirstName, member.LastName) ); } }
private void FixupMember(Member previousValue) { if (previousValue != null && previousValue.Partnerships.Contains(this)) { previousValue.Partnerships.Remove(this); } if (Member != null) { if (!Member.Partnerships.Contains(this)) { Member.Partnerships.Add(this); } if (ManagingMemberId != Member.MemberId) { ManagingMemberId = Member.MemberId; } } }
private void FixupMember(Member previousValue) { if (previousValue != null && previousValue.ApiAccesses.Contains(this)) { previousValue.ApiAccesses.Remove(this); } if (Member != null) { if (!Member.ApiAccesses.Contains(this)) { Member.ApiAccesses.Add(this); } if (MemberId != Member.MemberId) { MemberId = Member.MemberId; } } }
/* [HttpGet] public ActionResult FacebookLogin(string token) { var client = new WebClient(); string JsonResult = client.DownloadString(string.Concat("https://graph.facebook.com/me?access_token=", token)); var jsonUserInfo = JObject.Parse(JsonResult); // you can get more user's info here. Please refer to: // http://developers.facebook.com/docs/reference/api/user/ string username = jsonUserInfo.Value<string>("username"); string email = jsonUserInfo.Value<string>("email"); string locale = jsonUserInfo.Value<string>("locale"); string facebook_userID = jsonUserInfo.Value<string>("id"); // store user's information here... FormsAuthentication.SetAuthCookie(username, true); return RedirectToAction("Index", "Home"); } */ public ActionResult FacebookCallback(string code) { var fb = new FacebookClient(); dynamic result = fb.Post("oauth/access_token", new { client_id = BananaSplit.Core.Utility.Config.FacebookId, client_secret = BananaSplit.Core.Utility.Config.FacebookSecret, redirect_uri = RedirectUri.AbsoluteUri, code = code }); var accessToken = result.access_token; // 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,last_name,id,email"); string email = me.email; string fbId = me.id; var now = DateTime.Now; var memberRepo = new MemberRepository(); var member = memberRepo.GetByFacebookKey(fbId); if (null == member) { member = new Member(); member.FirstName = me.first_name; member.LastName = me.last_name; member.Email = email; member.FacebookId = fbId; member.DateCreated = now; member.MemberTypeId = 1; } member.DateUpdated = now; member.DateLastAccessed = now; memberRepo.Save(member); //TODO: Check via email to see if this user is authorized to be added. NEED A PAGE FOR THIS // Store the access token in the session Session["FBAccessToken"] = accessToken; Session["FBId"] = fbId; // Set the auth cookie //FormsAuthentication.SetAuthCookie(email, false); return RedirectToAction("Index", "Home"); }
public ActionResult SendSms() { var member = new Member(); member.FirstName = "Joe"; member.LastName = "Rosenblum"; Communication.SendSmsLoginResponse(member); var apiResult = new ApiResult {Success = true, Description = ""}; return this.ToXml(apiResult); }
private void FixupMember(Member previousValue) { if (previousValue != null && previousValue.PreLotteryOrders.Contains(this)) { previousValue.PreLotteryOrders.Remove(this); } if (Member != null) { if (!Member.PreLotteryOrders.Contains(this)) { Member.PreLotteryOrders.Add(this); } if (MemberId != Member.MemberId) { MemberId = Member.MemberId; } } }
private void FixupMember1(Member previousValue) { if (previousValue != null && previousValue.Invoices1.Contains(this)) { previousValue.Invoices1.Remove(this); } if (Member1 != null) { if (!Member1.Invoices1.Contains(this)) { Member1.Invoices1.Add(this); } if (MemberId != Member1.MemberId) { MemberId = Member1.MemberId; } } }