Exemplo n.º 1
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(" ", "") });

        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
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);

        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }