Пример #1
0
        public async Task <string> UploadPicture()
        {
            var logic   = new UserProfileLogic(db);
            var athlete = logic.GetAthleteForUserName(User.Identity.Name);

            var file = await Request.Content.ReadAsStreamAsync();

            if (file.Length < 100)
            {
                throw new Exception("file.Length=" + file.Length.ToString());
            }
            if (file.Length > 1000000 * 100)
            {
                throw new Exception("file.Length=" + file.Length.ToString());
            }

            string cloudinaryAccount = System.Web.Configuration.WebConfigurationManager.AppSettings["CloudinaryAccount"];
            string cloudinaryKey     = System.Web.Configuration.WebConfigurationManager.AppSettings["CloudinaryKey"];
            string cloudinarySecret  = System.Web.Configuration.WebConfigurationManager.AppSettings["CloudinarySecret"];
            var    cloudinary        = new CloudinaryDotNet.Cloudinary(new CloudinaryDotNet.Account(cloudinaryAccount, cloudinaryKey, cloudinarySecret));

            var uploadResult = await cloudinary.UploadAsync(new CloudinaryDotNet.Actions.ImageUploadParams()
            {
                File           = new CloudinaryDotNet.Actions.FileDescription("athlete" + athlete.AthleteID, file),
                Transformation = new Transformation().Width(500).Height(500).Crop("limit") // limit image size to 500x500 max
            });

            //string pictureUrl = uploadResult.Uri.ToString();
            string pictureUrl = "http://res.cloudinary.com/bestmybest/image/upload/" + uploadResult.PublicId + "." + uploadResult.Format;

            new UserProfileLogic(db).UpdateAthletePicture(athlete.AthleteID, pictureUrl);

            return(pictureUrl);
        }
Пример #2
0
        public string UseFacebookPicture(bool use)
        {
            var logic   = new UserProfileLogic(db);
            var athlete = logic.GetAthleteForUserName(User.Identity.Name);

            string pictureUrl = "";

            if (use == true && athlete.HasFacebookId)
            {
                pictureUrl = "http://res.cloudinary.com/bestmybest/image/facebook/" + System.Web.HttpUtility.UrlEncode(athlete.FacebookId) + ".jpg";
            }

            logic.UpdateAthletePicture(athlete.AthleteID, pictureUrl);
            return(pictureUrl);
        }
Пример #3
0
        public async Task <ChangePinResultWebModel> ChangePin(ChangePinWebModel model)
        {
            string newPin = model.Pin;

            if (new AccessPinHelper().Validate(newPin) == false)
            {
                throw new Exception("Bad pin");
            }

            var db        = new ApplicationDbContext();
            var logic     = new UserProfileLogic(db);
            var myAthlete = logic.GetAthleteForUserName(User.Identity.Name);

            string oldPin = logic.GetPin(myAthlete.AthleteID);

            logic.SetPin(myAthlete.AthleteID, newPin);

            // try changing the password
            // this will only work if the old pin was the password, otherwise this will fail and the password will stay
            try
            {
                var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), oldPin, newPin);

                if (result.Succeeded)
                {
                    return new ChangePinResultWebModel()
                           {
                               PinChanged = true, PasswordChanged = true
                           }
                }
                ;
            }
            catch (Exception)
            {
            }

            return(new ChangePinResultWebModel()
            {
                PinChanged = true, PasswordChanged = false
            });
        }