コード例 #1
0
        async System.Threading.Tasks.Task doAGraphReqest_Photo(string text, string publishToken, EventHandler <bool> done)
        {
            try
            {
                BasicFacebookProfileInfo facebookProfile = await this.GetBasicProfileInfo();

                var    parameters = new NSDictionary("picture", UIImage.FromFile("logo-512x512.png").AsPNG(), "caption", text);
                string userID     = facebookProfile.Id;
                string graphPath  = "/" + userID + "/photos";

                var request           = new Facebook.CoreKit.GraphRequest(graphPath, parameters, publishToken, null, "POST");
                var requestConnection = new GraphRequestConnection();
                requestConnection.AddRequest(request, (connection, result1, error1) => {
                    if (error1 != null)
                    {
                        done(this, false);
                        return;
                    }

                    string id = (result1 as NSDictionary)["post_id"].ToString();
                });
                requestConnection.Start();
            }
            catch (Exception)
            {
                done(this, false);
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> Register(Awpbs.RegisterWebModel model)
        {
            // temp: changing passwords on some accounts
            //try
            //{
            //    UserManager.ChangePassword("d786aeaf-6035-43eb-afb1-6a8c833f21cc", LoginHelper.BuildPasswordFromEmail_PreAugust2015("*****@*****.**"), LoginHelper.BuildLoginPasswordFromFacebookId("10153286890728926"));
            //    UserManager.ChangePassword("85747d20-d9c6-47b0-939f-b2279c0d9453", LoginHelper.BuildPasswordFromEmail_PreAugust2015("*****@*****.**"), LoginHelper.BuildLoginPasswordFromFacebookId("10102050416755296"));
            //    UserManager.ChangePassword("8958934d-ca86-420d-9116-c4082a59e9c1", LoginHelper.BuildPasswordFromEmail_PreAugust2015("*****@*****.**"), LoginHelper.BuildLoginPasswordFromFacebookId("10155681835300533"));
            //}
            //catch (Exception exc)
            //{
            //    int asdf = 15;
            //}

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // validate facebook's access token, if provided
            bool hasFacebook = string.IsNullOrEmpty(model.FacebookId) == false;
            BasicFacebookProfileInfo facebookProfileInfo = null;

            if (hasFacebook)
            {
                facebookProfileInfo = await FacebookAuthHelper.Validate(model.FacebookAccessToken);

                if (facebookProfileInfo == null)
                {
                    throw new Exception("Couldn't validate Facebook's access token");
                }
            }

            var db    = new ApplicationDbContext();
            var logic = new UserProfileLogic(db);

            // make sure that there is no user by this email in the system
            var existingUsersWithThisEmail = (from i in db.Athletes
                                              where i.RealEmail != null
                                              where i.RealEmail.ToLower() == model.Email.ToLower()
                                              select i).ToList();

            if (existingUsersWithThisEmail.Count > 0)
            {
                throw new Exception("There is already a user with this email");
            }

            // create a user
            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };
            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            // create athlete record
            string nameInFacebook = null;

            if (hasFacebook)
            {
                nameInFacebook = model.Name;
            }
            var athlete = logic.CreateAthleteForUserName(model.Email, model.FacebookId, nameInFacebook);

            logic.UpdateAthleteProfile(athlete.AthleteID, model.Name, (GenderEnum)model.Gender, model.DOB);
            if (hasFacebook && string.IsNullOrEmpty(facebookProfileInfo.EMail) == false)
            {
                logic.UpdateRealEmail(athlete.AthleteID, facebookProfileInfo.EMail);
            }

            // if the password fits the PIN format - use the password as the PIN
            if (new AccessPinHelper().Validate(model.Password))
            {
                logic.SetPin(athlete.AthleteID, model.Password);
            }

            // update picture
            string picture = null;

            if (hasFacebook)
            {
                picture = "http://res.cloudinary.com/bestmybest/image/facebook/" + HttpUtility.UrlEncode(model.FacebookId) + ".jpg";
            }
            if (picture != null)
            {
                logic.UpdateAthletePicture(athlete.AthleteID, picture);
            }

            return(Ok());
        }