示例#1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            await ReCapchaVerification();

            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                var ResetPasswordVM = new GenericEmailViewModel {
                    RootURL = GetRootURL()
                };

                await BusinessLogic.UserLogic.ResetPassword(ResetPasswordVM, user, callbackUrl);

                db.SaveChanges();
                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (!model.AcceptTAndCs)
            {
                ModelState.AddModelError("AcceptTAndCs", "You Must Accept The Terms & Conditions");
            }

            await ReCapchaVerification();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName                = model.Username,
                    Email                   = model.Email,
                    ProfilePictureID        = model.ProfilePictureImageID,
                    RecieveThirdPartyEmails = model.ThirdPartyEmails,
                    RecieveFirstPartyEmails = model.FirstPartyEmails,
                    IsCompany               = model.IsCorporate,
                    IsExercisor             = model.IsExercisor,
                    IsSponsor               = model.IsSponsor
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    string code        = UserManager.GenerateEmailConfirmationToken(user.Id);
                    var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                    var reloadedUser = db.Users.FirstOrDefault(u => u.Id == user.Id);

                    var WelcomeVM = new GenericEmailViewModel {
                        RootURL = GetRootURL()
                    };

                    await BusinessLogic.UserLogic.ConfigureNewUser(reloadedUser, WelcomeVM, callbackUrl);

                    db.SaveChanges();

                    if (reloadedUser.IsExercisor)
                    {
                        return(RedirectToAction("RegisterFurtherDetails"));
                    }

                    if (reloadedUser.IsSponsor)
                    {
                        return(RedirectToAction("RegisterJustGiving"));
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        private async Task <ActionResult> FacebookLoginNewUser(ExternalLoginInfo loginInfo)
        {
            // create user object
            var user = new ApplicationUser {
                UserName = loginInfo.ExternalIdentity.Name.Substring(0, Math.Min(10, loginInfo.ExternalIdentity.Name.Length)), Email = loginInfo.Email
            };

            //grab profile pic and add to db
            user.ProfilePictureID = BusinessLogic.ImageLogic.GetAndSaveImageFromURL($"https://graph.facebook.com/{loginInfo.Login.ProviderKey}/picture",
                                                                                    CalorieImage.ImageType.UserImage);

            user.IsExercisor = true;
            user.IsSponsor   = true;

            //persist user
            var NewUserResult = await UserManager.CreateAsync(user);

            if (NewUserResult.Succeeded)
            {
                var AddLogInResult = await UserManager.AddLoginAsync(user.Id, loginInfo.Login);

                if (AddLogInResult.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    var reloadeduser = db.Users.FirstOrDefault(u => u.Id == user.Id);

                    string code        = UserManager.GenerateEmailConfirmationToken(reloadeduser.Id);
                    var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = reloadeduser.Id, code = code }, protocol: Request.Url.Scheme);

                    var WelcomeVM = new GenericEmailViewModel {
                        RootURL = GetRootURL()
                    };

                    await BusinessLogic.UserLogic.ConfigureNewUser(reloadeduser, WelcomeVM, callbackUrl);

                    db.SaveChanges();

                    return(RedirectToAction("RegisterFurtherDetails"));
                }
            }

            //if we're here then something went wrong
            var Comment = new System.Text.StringBuilder();

            Comment.Append("Tried to create a new user but encountered the following issues:-" + Environment.NewLine);
            foreach (var e in NewUserResult.Errors)
            {
                Comment.Append(e);
            }

            ViewBag.Message = Comment.ToString();
            return(View("ExternalLoginFailure"));
        }
示例#4
0
        public static async Task <bool> ResetPassword(GenericEmailViewModel ResetPasswordVM, ApplicationUser user, string CallbackURL)
        {
            ResetPasswordVM.Name             = user.UserName;
            ResetPasswordVM.HTMLContent      = "A password reset has been requested on your account";
            ResetPasswordVM.PlaintextMessage = ResetPasswordVM.HTMLContent;
            ResetPasswordVM.Buttons.Add(new GenericEmailButtonViewModel {
                Text = "Reset Password", URL = CallbackURL
            });


            return(await Messaging.SendEmail("Account Password Reset", ResetPasswordVM.PlaintextMessage, Utilities.RenderGenericEmalHTML(ResetPasswordVM), user.Email));
        }
示例#5
0
        public async Task <ActionResult> ApproveJoinRequests(List <string> IDs, int thisTeamID)
        {
            var team = db.Teams.FirstOrDefault(t => t.ID == thisTeamID);

            if (team == null)
            {
                Messaging.Add(Message.LevelEnum.alert_danger, "something went wrong trying to approve users. please try again.", Message.TypeEnum.TemporaryAlert, CurrentUser());
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            if (IDs == null)
            {
                Messaging.Add(Message.LevelEnum.alert_danger, "something went wrong trying to approve users. please try again.", Message.TypeEnum.TemporaryAlert, CurrentUser());
                db.SaveChanges();
                return(RedirectToAction("Details", new { teamname = team.Name.Replace(" ", "") }));
            }

            foreach (string ID in IDs)
            {
                var user = db.Users.FirstOrDefault(u => u.Id == ID);
                if (user != null)
                {
                    user.TeamID = thisTeamID;
                }
                var TJR = db.TeamJoinRequests.FirstOrDefault(JR => JR.UserID == ID && JR.TeamID == thisTeamID);
                if (TJR != null)
                {
                    db.TeamJoinRequests.Remove(TJR);
                }
            }

            var EmailVM = new GenericEmailViewModel {
                RootURL = GetRootURL()
            };

            var TeamURL = Url.Action("Details", "Teams", new { teamname = team.Name.Replace(" ", "") }, Request.Url.Scheme);

            foreach (string ID in IDs)
            {
                var user = db.Users.FirstOrDefault(u => u.Id == ID);
                if (user != null)
                {
                    await UserLogic.JoinTeamRequestApproved(user, team, EmailVM, TeamURL);
                }
            }

            Messaging.Add(Message.LevelEnum.alert_success, string.Format("{0} new members successfully approved", IDs.Count()), Message.TypeEnum.StickyAlert, CurrentUser());
            db.SaveChanges();
            return(RedirectToAction("Details", new { teamname = team.Name.Replace(" ", "") }));
        }
示例#6
0
        public static async Task <bool> ConfigureNewUser(ApplicationUser User, GenericEmailViewModel EmailVM, string ConfirmEmailURL)
        {
            var Msg = "Thanks for singing up!" + Environment.NewLine + Environment.NewLine +
                      "Please check your email for a link to confirm your email address.";

            Messaging.Add(Message.LevelEnum.alert_success, Msg, Message.TypeEnum.StickyAlert, User);

            EmailVM.Name             = User.UserName;
            EmailVM.HTMLContent      = "Welcome to ChariFit, thanks for signing up.<br/><br/>Please confirm your email address by clicking below";
            EmailVM.PlaintextMessage = $"Welcome to ChariFit, thanks for signing up. Please confirm your email address by going to this address: {ConfirmEmailURL}";
            EmailVM.Buttons.Add(new GenericEmailButtonViewModel {
                Text = "Confirm Email Address", URL = ConfirmEmailURL
            });

            return(await Messaging.SendEmail("Welcome To ChariFit", EmailVM.PlaintextMessage, Utilities.RenderGenericEmalHTML(EmailVM), User.Email));
        }
示例#7
0
        public static async Task <bool> JoinTeamRequestApproved(ApplicationUser user, Team team, GenericEmailViewModel EmailVM, string teamURL)
        {
            Messaging.Add(Message.LevelEnum.alert_success, string.Format("Your membership of team '{0}' has been approved.", team.Name), Message.TypeEnum.StickyAlert, user);

            if (!user.RecieveFirstPartyEmails)
            {
                return(true);
            }

            EmailVM.Name             = user.UserName;
            EmailVM.HTMLContent      = "<p>Congratulations! <br/>" + string.Format("<p>Your request to join team '{0}' has been approved by the Administrator", team.Name);
            EmailVM.PlaintextMessage = EmailVM.HTMLContent.Replace("<br/>", Environment.NewLine);
            EmailVM.Buttons.Add(new GenericEmailButtonViewModel {
                Text = "Go To Team", URL = teamURL
            });

            return(await Messaging.SendEmail("Membership Approved", EmailVM.PlaintextMessage, Utilities.RenderGenericEmalHTML(EmailVM), user.Email));
        }
示例#8
0
        public static async Task <bool> ConfigureNewJustGivingAccount(ApplicationUser User, GenericEmailViewModel JustGivingSignUpEmailVM, string Password)
        {
            JustGivingSignUpEmailVM.Name        = User.UserName;
            JustGivingSignUpEmailVM.HTMLContent =
                "We have created a JustGiving Account for you with the following details:-<br/><br/>" +
                $"Email Address: {User.Email}<br/>" + $"Password: {Password}<br/><br/><br/>" +
                "Please note that ChariFit will not keep a record of your password." + "<br/>" +
                "We strongly suggest you change this password now.";

            JustGivingSignUpEmailVM.PlaintextMessage = JustGivingSignUpEmailVM.HTMLContent.Replace("<br/>", Environment.NewLine);

            JustGivingSignUpEmailVM.Buttons.Add(new GenericEmailButtonViewModel {
                Text = "Change Password", URL = "https://www.justgiving.com/account/your-details#update-your-password"
            });


            await Messaging.SendEmail("JustGiving Account Details", JustGivingSignUpEmailVM.PlaintextMessage, Utilities.RenderGenericEmalHTML(JustGivingSignUpEmailVM), User.Email);


            var Msg = "A JustGiving account has been created for you, check your email for details.";

            Messaging.Add(Message.LevelEnum.alert_success, Msg, Message.TypeEnum.StickyAlert, User);
            return(true);
        }
示例#9
0
        public async Task <ActionResult> RegisterJustGiving(RegisterJustGiving model)
        {
            //add email, password and accepttandc

            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var body = new
            {
                acceptTermsAndConditions = true,
                address = new
                {
                    country           = model.country,
                    line1             = model.AddressLine1,
                    line2             = model.AddressLine2,
                    postcodeOrZipcode = model.postcodeOrZip,
                    townOrCity        = model.AddressTownOrCity,
                },
                email     = CurrentUser()?.Email,
                firstName = model.firstname,
                lastName  = model.lastname,
                password  = Guid.NewGuid().ToString("d").Replace("-", "").Substring(1, 15),
                //reference="Your Reference",
                title = model.title
            };

            var result = await BusinessLogic.GenericLogic.HttpPut(body, ConfigurationManager.AppSettings["JustGivingAPIURL"] + ConfigurationManager.AppSettings["JustGivingAppId"] + "/v1/account");

            var resultStr = await result.Content.ReadAsStringAsync();

            if (result.StatusCode == HttpStatusCode.OK)
            {
                var JustGivingSignUpEmailVM = new GenericEmailViewModel {
                    RootURL = GetRootURL()
                };

                await BusinessLogic.UserLogic.ConfigureNewJustGivingAccount(CurrentUser(), JustGivingSignUpEmailVM, body.password);

                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            if (result.StatusCode == HttpStatusCode.BadRequest)
            {
                dynamic jsonresponse = System.Web.Helpers.Json.Decode(resultStr);
                foreach (var item in jsonresponse)
                {
                    string value = item.Value;
                    string desc  = string.Empty;

                    try
                    {
                        desc = item.desc;
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    if (value == null)
                    {
                        ModelState.AddModelError("Registration Message", "JustGiving says.. " + desc);
                    }
                    else
                    {
                        ModelState.AddModelError("Registration Message", "JustGiving says.. " + value);
                    }
                }
            }
            else if (result.StatusCode == HttpStatusCode.InternalServerError)
            {
                ModelState.AddModelError("Registration Message", "JustGiving spazzed out. Try again later");
            }

            return(View(model));
        }