Exemplo n.º 1
0
        private async Task RegisterReservationUser(List <string> userNames, Reservation reservation)
        {
            if (userNames == null)
            {
                return;
            }

            foreach (var userName in userNames)
            {
                var user = _context.Users.FirstOrDefault(c => c.UserName == userName);
                if (user == null)
                {
                    continue;
                }

                var item = new ReservationUser()
                {
                    UserId      = user.Id,
                    Reservation = reservation
                };

                _context.ReservationUsers.Add(item);
                _reservationService.OnAddReservationUser(item);
            }
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
 public void OnRemoveReservationUser(ReservationUser item)
 {
     if (_options.IsOutgoingEnabled)
     {
         var data       = item.ToApiModel();
         var dataString = JsonConvert.SerializeObject(data);
         NotifyToOutgoing("RemoveReservationUser", dataString);
     }
 }
Exemplo n.º 3
0
        public static Tuple <IdNamePair <string>, ReservationResponse> ToApiModel(this ReservationUser model)
        {
            var temp = new Tuple <IdNamePair <string>, ReservationResponse>(
                new IdNamePair <string>()
            {
                Id   = model.UserId,
                Name = model.User.UserName
            },
                model.Reservation.ToApiModel());

            return(temp);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new ReservationUser {
                    UserName = Input.Email, Email = Input.Email, FName = Input.FName, LName = Input.LName, Classe = Input.Classe
                };
                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);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        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>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        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());
        }