Example #1
0
 public UserModel(MyMeetupUser user)
 {
     Id                   = user.Id;
     FirstName            = user.FirstName;
     LastName             = user.LastName;
     Email                = user.Email;
     IsOkToGetMeetupsInfo = user.IsOkToGetMeetupsInfo;
 }
Example #2
0
        public ActionResult Index(SigninMeetupModel model, [FromServices] SignInManager <MyMeetupUser> signInManager, [FromServices] IConfiguration configuration)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", CreateLandingPageModel(model)));
            }

            MyMeetupUser user = UserManager.FindByEmailAsync(model.Email.Trim()).Result;

            if (user != null)
            {
                return(View("MyAccount", GetMyAccountModel(configuration, user)));
            }
            var result = Domain.AddRegularUser(model, null, UserManager);

            if (result.UserOk)
            {
                user = UserManager.FindByEmailAsync(model.Email).Result;
                SendEmail     se    = new SendEmail();
                MyMeetupEmail email = new MyMeetupEmail($"Nouvel Adhérent {model.FirstName} {model.Name} ",
                                                        configuration["emailContact"], configuration["emailContact"])
                {
                    Body = $"Prénom :{model.FirstName} <br/>Nom :{model.Name} - <br/>Email : {model.Email} <br/>Tel: {model.PhoneNumber}"
                };
                //TODO Ugly, should be templated
                if (!string.IsNullOrEmpty(result.RegistrationCode))
                {
                    var meetup = Domain.GetMeetup(model.MeetupId.Value, true);
                    email.Body += Environment.NewLine +
                                  $"Inscrit(e) à {meetup.Title} et son code d'enregistrement est {result.RegistrationCode}";
                }
                email.ReplyTo = model.Email;
                try
                {
                    if (!Debugger.IsAttached)
                    {
                        se.SendSmtpEmail(EmailSender.GetSettings(configuration), email);
                    }
                }
                catch (Exception e)
                {
                    _telemetryClient.TrackException(e);
                }

                signInManager.SignInAsync(user, isPersistent: true).Wait();
                //   signInManager.SignInAsync(user, isPersistent: true);
                if (model.MeetupId.HasValue)
                {
                    return(RedirectToAction("Register", new { meetupId = model.MeetupId.Value }));
                }

                return(RedirectToAction("MyAccount"));
                //     return View("MyAccount", GetMyAccountModel(configuration, user));
            }

            return(View("Index", CreateLandingPageModel()));
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync([FromServices] UserManager <MyMeetupUser> userManager, [FromServices] MyMeetupContext context, string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                MyMeetupUser user = userManager.FindByEmailAsync(Input.Email).Result;
                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, $"Email {Input.Email} inconnu.");
                    return(Page());
                }
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                SignInResult result = await _signInManager.PasswordSignInAsync(user.UserName, Input.Password.Trim(), Input.RememberMe, lockoutOnFailure : true);

                bool isLoginOk = result.Succeeded;
                if (!isLoginOk && !result.IsLockedOut && !result.IsNotAllowed)
                {
                    if (context.Registrations.Any(x => x.UserId == user.Id && x.RegistrationCode == Input.Password.Trim()))
                    {
                        await _signInManager.SignInAsync(user, Input.RememberMe);

                        isLoginOk = true;
                    }
                }
                if (isLoginOk)
                {
                    _logger.LogInformation($"User {Input.Email} logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Mauvais mot de passe.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #4
0
        private MyAccountModel GetMyAccountModel(IConfiguration configuration, MyMeetupUser currentUser = null)
        {
            MyAccountModel model = new MyAccountModel(currentUser ?? CurrentUser);

            model.Payments = Domain.GetPayments(model.CurrentUser?.Id ?? -1, true);
            List <Registration> regs = Domain.GetRegistrations(model.CurrentUser.Id, true)
                                       .Where(x => x.RegistrationStatus <= ERegistrationStatus.Registered)
                                       .OrderBy(x => x.Meetup.StartDate).ToList();

            model.OldMeetups = regs.Where(x => x.Meetup.EndDate <= DateTime.Now).ToList();
            var nextRegistrations = regs.Where(x => x.Meetup.StartDate > DateTime.Now).ToList();

            if (nextRegistrations.Any() == false)
            {
                model.NextRegistrations = "Tu n'as aucune rencontre de prévue !";
            }
            else
            {
                model.NextRegistrations = "Tu es pré-inscrit-e à : <ul> ";
                List <string> texts = new List <string>();
                foreach (var reg in regs)
                {
                    string tmp = $"<li>{reg.Meetup.Title} (qui commence le {reg.Meetup.StartDate:dd MMMM yyyy}) : ";
                    if (reg.RegistrationStatus == ERegistrationStatus.Preregistration)
                    {
                        tmp += $"ton code d'enregistrement sera envoyé à {model.CurrentUser.Email}";
                    }
                    else
                    {
                        tmp += $"ton code d'enregistrement est {reg.RegistrationCode} pour {reg.NumberOfAdults} adultes, {reg.NumberOfChildren} dans {reg.AccomodationId}";
                    }
                    texts.Add(tmp + "</li>");
                }

                model.NextRegistrations += Environment.NewLine + String.Join("", texts) + Environment.NewLine + "</ul>";
            }
            List <Meetup> meetups = Domain.GetNextMeetups(DateTime.Now.Date, true);

            foreach (Meetup m in meetups)
            {
                var vm = new NextMeetupView(m);
                if (!regs.Any(x => x.MeetupId == vm.MeetupId))
                {
                    model.NextMeetups.Add(vm);
                }
            }
            return(model);
        }
Example #5
0
        public IActionResult Edit(UserEditModel model, string chkSupprimer, [FromServices] IMapper mapper)
        {
            bool aSupprimer = chkSupprimer == "on";

            if (aSupprimer)
            {
                Domain.DeleteUserTotally(model.Id, UserManager);
                return(Redirect(model.BackUrl));
            }
            else
            {
                MyMeetupUser user = mapper.Map <MyMeetupUser>(model);
                Domain.ModifyUser(user);
            }

            return(View("Details", GetUserDetails(model.Id, model.BackUrl)));
        }
        private async Task LoadSharedKeyAndQrCodeUriAsync(MyMeetupUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
Example #7
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new MyMeetupUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

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

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
Example #8
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new MyMeetupUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #9
0
 public MyAccountModel(MyMeetupUser user)
 {
     CurrentUser = user;
 }