Exemplo n.º 1
0
        public async Task <ExternalLoginInfo> GetExternalLoginConfirmationAsync(UserExternalLoginViewModel model, string returnUrl = null)
        {
            var info = await signInManager.GetExternalLoginInfoAsync();

            var facebookData = await this.facebookService.GetFacebookInfoAsync();

            byte[] pictureInBytes = Encoding.ASCII.GetBytes(facebookData[2]);

            var user = new FastFoodUser {
                UserName = model.Email, Email = model.Email, FirstName = facebookData[0], LastName = facebookData[1], Picture = pictureInBytes
            };

            var result = await userManager.CreateAsync(user);

            await this.userManager.AddToRoleAsync(user, StringConstants.UserRole);

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

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

            return(info);
        }
Exemplo n.º 2
0
        public async Task RegisterUserAsync(UserRegisterViewModel model)
        {
            FastFoodUser user = null;

            try
            {
                user = this.mapper.Map <FastFoodUser>(model);

                user.Picture = await model.Picture.UploadAsync();

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

                if (result.Succeeded)
                {
                    var code = this.userManager.GenerateEmailConfirmationTokenAsync(user);
                    await this.userManager.AddToRoleAsync(user, StringConstants.UserRole);

                    await this.signInManager.SignInAsync(user, isPersistent : false);

                    this.logger.LogInformation(LogMessages.UserWasCreated);
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }
        }
Exemplo n.º 3
0
        public Task <FastFoodUser> CreateManagerAsync(
            string firstName,
            string lastName,
            string userName,
            string dateOfBirth,
            string address,
            string email,
            string phoneNumber)
        {
            DateTime     birthDate;
            FastFoodUser manager = null;

            try
            {
                birthDate = DateTime.ParseExact(dateOfBirth, "dd-MM-yyyy", CultureInfo.InvariantCulture);

                manager = new FastFoodUser()
                {
                    UserName    = userName,
                    FirstName   = firstName,
                    LastName    = lastName,
                    BirthDate   = birthDate,
                    Address     = address,
                    Email       = email,
                    PhoneNumber = phoneNumber,
                };
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }

            return(Task.FromResult <FastFoodUser>(manager));
        }
Exemplo n.º 4
0
        public void AuthenicateUserAsync(FastFoodUser user, Action <bool> completed)
        {
            this.SendPacket(new AuthenicateUserOutgoingPacket(user), (c) =>
            {
                if (c)
                {
                    ReceivedPacket delegate_ = null;
                    delegate_ = delegate(IncomingPacket packet)
                    {
                        AuthenicateUserResponseIncomingPacket auth = packet as AuthenicateUserResponseIncomingPacket;
                        if (auth?.Result ?? false)
                        {
                            user.SetSessionToken(auth.SessionToken);

                            completed?.Invoke(true);
                        }
                        else
                        {
                            completed?.Invoke(false);
                        }

                        this.UnregisterPacketListenerUnsafe(delegate_);
                    };

                    this.RegisterPacketListenerUnsafe(delegate_);
                }
                else
                {
                    completed?.Invoke(false);
                }
            });
        }
Exemplo n.º 5
0
        public void Handle(BaseConnection connection, BinaryReader packet)
        {
            APIConnection api = connection as APIConnection;

            if (api?.PrivateAPIUsable ?? false)
            {
                uint            userId      = packet.ReadUInt32();
                GamePowerupType powerupType = (GamePowerupType)packet.ReadByte();
                int             amount      = packet.ReadInt32();

                FastFoodUser user = api.Hotel.GetUser(userId);
                if (user != null)
                {
                    switch (powerupType)
                    {
                    case GamePowerupType.Missile:
                        user.Missiles = amount;
                        break;

                    case GamePowerupType.Parachute:
                        user.Parachutes = amount;
                        break;

                    case GamePowerupType.Shield:
                        user.Shields = amount;
                        break;
                    }

                    Dictionary <int, int> powerups = new Dictionary <int, int>();
                    if (user.Missiles > 0)
                    {
                        powerups.Add(UserPowerupsOutgoingPacket.Missile, user.Missiles);
                    }

                    if (user.Parachutes > 0)
                    {
                        powerups.Add(UserPowerupsOutgoingPacket.Parachute, user.Parachutes);
                    }

                    if (user.Shields > 0)
                    {
                        powerups.Add(UserPowerupsOutgoingPacket.Shield, user.Shields);
                    }

                    user.GameConnection?.SendPacket(new UserPowerupsOutgoingPacket(powerups));
                }
            }
        }
Exemplo n.º 6
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 facebookData = await facebookService.GetFacebookInfo();

                var user = new FastFoodUser {
                    UserName = Input.Email, Email = Input.Email, FirstName = facebookData[0], LastName = facebookData[1]
                };
                var result = await _userManager.CreateAsync(user);

                await _userManager.AddToRoleAsync(user, CommonStrings.UserRole);

                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());
        }
        public void Handle(BaseConnection connection, BinaryReader packet)
        {
            APIConnection api = connection as APIConnection;

            if (api?.PrivateAPIUsable ?? false)
            {
                uint userId  = packet.ReadUInt32();
                int  credits = packet.ReadInt32();

                FastFoodUser user = api.Hotel.GetUser(userId);
                if (user != null)
                {
                    user.Credits = credits;

                    user.GameConnection?.SendPacket(new CreditsOutgoingPacket(credits));
                }
            }
        }
Exemplo n.º 8
0
        public FastFoodUser CreateManager(
            string firstName,
            string lastName,
            string userName,
            string dateOfBirth,
            string address,
            string email)
        {
            var birthDate = DateTime.ParseExact(dateOfBirth, "dd-MM-yyyy", CultureInfo.InvariantCulture);

            var manager = new FastFoodUser()
            {
                UserName  = userName,
                FirstName = firstName,
                LastName  = lastName,
                BirthDate = birthDate,
                Address   = address,
                Email     = email,
            };

            return(manager);
        }
 public AuthenicateUserOutgoingPacket(FastFoodUser user)
 {
     this.User = user;
 }
Exemplo n.º 10
0
        public string AuthenicateUser(FastFoodUser user)
        {
            this.Users.AddOrUpdate(user.UserID, user, (key, value) => user);

            return(Server.GetGame().GetSessionManager().CreateSSOTicket(this, user.UserID));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            IFormFile formFile = null;

            if (HttpContext.Request.Form.Files.Count > 0)
            {
                formFile = HttpContext.Request.Form.Files[0];
            }

            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new FastFoodUser
                {
                    FirstName = Input.FirstName,
                    LastName  = Input.LastName,
                    UserName  = Input.Username,
                    Address   = Input.Address,
                    BirthDate = Input.DateOfBirth,
                    Email     = Input.Email,
                };

                if (formFile != null)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        await formFile.CopyToAsync(memoryStream);

                        user.Picture = memoryStream.ToArray();
                    }
                }

                var result = await _userManager.CreateAsync(user, Input.Password);

                await this._userManager.AddToRoleAsync(user, CommonStrings.UserRole);

                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());
        }