Beispiel #1
0
 private void materialButton1_Click(object sender, EventArgs e)
 {
     if (user.Checked == true)
     {
         CarService.Users.ToList().ForEach(user =>
         {
             if (user.Value.GetLogin()
                 == logingTextBox.Text && user.Value.GetPassword() == passwordTextBox.Text)
             {
                 authorizedUser = CarService.Users[user.Key];
             }
         });
         if (authorizedUser == null)
         {
             authorizedUser = new ClientUser(logingTextBox.Text, passwordTextBox.Text, Guid.NewGuid().ToString());
             CarService.Users.Add(authorizedUser.GetId(), authorizedUser);
         }
         Form1 frm = new Form1(authorizedUser, CarService);
         frm.Show();
     }
     else
     {
         authorizedUser = new AdminUser();
         Form1 mainForm = new Form1(authorizedUser, CarService);
         mainForm.Show();
     }
     UserRepository.writeFile(CarService.Users);
 }
Beispiel #2
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            IAuthorizedUser user = await _oauthDataManager.GetUserByUserIdAndPassword(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim(ClaimTypes.Name, user.UserId));

            string[] roles = await _oauthDataManager.GetRolesForUser(user);

            foreach (string role in roles)
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, role));
            }

            var props = new AuthenticationProperties(new Dictionary <string, string>
            {
                { "client_id", context.ClientId ?? string.Empty },
                { "userName", user.UserId ?? string.Empty },
                { "displayName", user.DisplayName ?? string.Empty },
                { "permissions", string.Join(",", roles) }
            });

            var ticket = new AuthenticationTicket(identity, props);

            context.Validated(ticket);
            await _oauthDataManager.UpdateUserLastActivityDate(user);
        }
 public Task <string[]> GetRolesForUser(IAuthorizedUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     return(Task.FromResult(_defaultAuthUsers.Where(x => x.UserId == user.UserId).Select(x => x.Roles).FirstOrDefault()));
 }
Beispiel #4
0
 public OrderWizard(CarSharingService service, Car car, IAuthorizedUser user, updateUI updateWidth, updateUI updateList)
 {
     InitializeComponent();
     CarSharingService = service;
     itemToOrder       = car;
     authorizedUser    = user;
     UpdateWidth       = updateWidth;
     UpdateList        = updateList;
 }
        public UserUI(CarSharingService carSharing, IAuthorizedUser user)
        {
            InitializeComponent();
            carSharingService = carSharing;
            reloadList();
            User = user;

            MaxListWidth();
            setOrderUI(user);
        }
        public void generateAdminForm(CarSharingService carSharingService, IAuthorizedUser user)
        {
            AdminUI ui = new AdminUI(carSharingService, user);

            ui.Location = new System.Drawing.Point(0, 64);
            ui.Name     = "adminUI1";
            ui.Size     = new System.Drawing.Size(1100, 662);
            ui.TabIndex = 1;
            Controls.Add(ui);
        }
        public Task UpdateUserLastActivityDate(IAuthorizedUser user)
        {
            DefaultAuthUser defaultAuthUser = _defaultAuthUsers.FirstOrDefault(x => x.UserId == user.UserId);

            if (defaultAuthUser != null)
            {
                defaultAuthUser.LastLoggedIn = DateTime.Now;
            }
            return(Task.FromResult(true));
        }
        public Form1(IAuthorizedUser user, CarSharingService carSharingService)
        {
            carService = carSharingService;
            if (user.IsAdmin())
            {
                generateAdminForm(carSharingService, user);
            }
            else
            {
                generateUserForm(carSharingService, user);
            }

            InitializeComponent();
        }
        public AdminUI(CarSharingService carSharing, IAuthorizedUser user)
        {
            InitializeComponent();
            carSharingService = carSharing;
            List <ListItem> list = new List <ListItem>();

            carSharingService.Cars.ToList().ForEach(item => list.Add(new ListItem(this, item.Value)));
            ItemList.Controls.AddRange(list.ToArray());
            User = user;

            List <OrderItem> orderItems = new List <OrderItem>();

            CarSharingService.Orders.ToList().ForEach(item => orderItems.Add(new OrderItem(carSharingService, item.Value, orderList)));
            orderList.Controls.AddRange(orderItems.ToArray());
        }
 public void setOrderUI(IAuthorizedUser user)
 {
     if (user.GetOrder() == null)
     {
         noOrderCard.Visible = true;
         orderCard.Visible   = false;
     }
     else
     {
         noOrderCard.Visible    = false;
         orderCard.Visible      = true;
         orderImage.Image       = user.GetOrder().Car.Image;
         orderBrandLabel.Text   = user.GetOrder().Car.Brand;
         orderModelLabel.Text   = user.GetOrder().Car.Model;
         orderCommentLabel.Text = user.GetOrder().Car.Comment;
         startDateLabel.Text    = user.GetOrder().StartDate;
         endDateLabel.Text      = user.GetOrder().EndDate;
     }
 }
Beispiel #11
0
 public NancyIdentity(IAuthorizedUser authorizedUser)
 {
     this.authorizedUser = authorizedUser;
 }