Ejemplo n.º 1
0
        public IActionResult Edit(int id)
        {
            using RDATContext context = new RDATContext();

            CreateDriverViewModel _model = new CreateDriverViewModel();

            // Get User Roles
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            _model.IsReadOnly = currentUser.IsInRole("ReadOnly");

            Driver _driver = context.Drivers.Where(d => d.Id == id).FirstOrDefault();

            ViewBag.CompanyName = _driver.DriverName;

            List <SelectListItem> states = context.States.OrderBy(s => s.StateName).Select(a =>
                                                                                           new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.StateName
            }).ToList();

            _model.States = states;

            _model.Driver = _driver;

            return(View(_model));
        }
Ejemplo n.º 2
0
        public static HtmlString BuildCommentList(int id, System.Security.Claims.ClaimsPrincipal claims)
        {
            string result = "", Image = "", Delete = "";

            foreach (var obj in VirtualBD.Comments)
            {
                if (obj.articleID == id)
                {
                    if (claims.IsInRole(Role.Admin) || claims.Identity.Name == obj.Creator)
                    {
                        Delete = $"<div class=\"col text-right\"> <button class=\"delete btn btn-danger\" id=\"{obj.ID}\" data=\"/Articles/deleteComment\">Удалить</button></div>";
                    }

                    if (obj.Img != null)
                    {
                        Image = $"<img src=\"{obj.Img}\" style=\"max-width:220px;\">";
                    }
                    else
                    {
                        Image = "";
                    }

                    result += $" <div class=\"row CommentTooArticle\" style=\"margin-top:25px; margin-bottom:10px; \"> <div class=\"col\">";
                    result += $" <div class=\"row border-bottom:1px solid black;\"> <div class=\"col-auto\"><img src = \"{@VirtualBD.Users.Find(x => x.Email == obj.Creator).Image}\" width=\"25\" height=\"25\"></div> <div class=\"col-auto\"> <a href=\"/Account/UserProfil?name={obj.Creator}\">{obj.Name} </a> </div> <div class=\"col-auto\">{obj.Time}</div></div>";
                    result += $"<div class=\"row\" style=\"margin-top: 15px;\"> <div class=\"col\"> {Image} <div>{obj.text}</div> </div> {Delete} </div>";
                    result += $"</div> </div> ";
                }
            }
            return(new HtmlString(result));
        }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            bool     IsAdmin = currentUser.IsInRole("Admin"); // might use this in future
            var      Uid     = userManager.GetUserId(User);   // Get user id:
            UserInfo usrinfo = _context.UserInfos.SingleOrDefault(p => p.ApplicationUserId == Uid);

            if (usrinfo != null)
            {
                //
                var countries = _context.Countries.ToList();
                var vm        = new UserInfoFormViewModel
                {
                    userinfo  = usrinfo,
                    countries = countries
                };
                return(View("Welcome", vm));
            }
            else
            {
                // the user needs to Create a UserInfo profile
                var ui        = new UserInfo {
                    //ApplicationUserId = Uid
                };
                var countries = _context.Countries.ToList();
                var vm        = new UserInfoFormViewModel
                {
                    userinfo  = ui,
                    countries = countries
                };
                return(View("UserInfoForm", vm));
            }
        }
        public void SaveOrder(List <Matratt> matratter, int userid, System.Security.Claims.ClaimsPrincipal user)
        {
            var count = matratter.Count;

            if (user.IsInRole("PremiumUser"))
            {
                SaveOrderPremiumUser(matratter, userid);
            }
            else
            {
                var customer    = GetById(userid);
                var totalmoney  = GetTotalPayment(matratter);
                var bestallning = new Bestallning()
                {
                    BestallningDatum = DateTime.Now,
                    KundId           = customer.KundId,
                    Totalbelopp      = totalmoney,
                    Levererad        = false
                };


                using (TomasosContext db = new TomasosContext())
                {
                    db.Add(bestallning);
                    db.SaveChanges();
                }
                SaveBestallningMatratter(matratter);
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> IndexAsync()
        {
            List <ClientJobViewModel> model = new List <ClientJobViewModel>();

            if (!_signInManager.IsSignedIn(User))
            {
                return(Redirect("~/Account/LoginClient"));
            }
            else
            {
                System.Security.Claims.ClaimsPrincipal currentUser = User;
                var isClient = currentUser.IsInRole("client") || currentUser.IsInRole("client-editor");

                if (isClient)
                {
                    var user = await _userManager.GetUserAsync(User);

                    var client = _clientRepository.GetClientByUserId(user.Id);

                    IEnumerable <Job> jobs = _jobsRepository.Find(x => x.ClientId == client.Id);

                    foreach (var job in jobs)
                    {
                        ClientJobViewModel clientjobmodel = new ClientJobViewModel();
                        var jobcategory = _jobCategoryRepository.GetById(job.JobCategoryId);
                        clientjobmodel.JobId              = job.Id;
                        clientjobmodel.JobTitle           = jobcategory.CategoryName_JP;
                        clientjobmodel.JapaneseLevel      = job.JapaneseLevel_Text;
                        clientjobmodel.Workinghour        = job.Workinghour;
                        clientjobmodel.WorkingDaysPerWeek = job.WorkingdaysPerweek;
                        //clientjobmodel.ContractType = job.WorkinghourPerday;
                        clientjobmodel.Address      = job.WorkLocationAddress;
                        clientjobmodel.ProvinceName = job.provinceName;
                        clientjobmodel.Salary       = job.Salary_Hourly;
                        clientjobmodel.PostDate     = job.PostDate;
                        clientjobmodel.Status       = job.Status;
                        var jobapplied = _jobApplyRepository.GetAppliedCount(job.Id);
                        clientjobmodel.CandidateApplied = jobapplied.Count;
                        model.Add(clientjobmodel);
                    }

                    return(View(model));
                }
            }

            return(Redirect("~/Account/LoginClient"));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
            {
                var user = UserManager.FindByName(model.Username);
                if (user != null)
                {
                    Session["UserName"] = user.FirstName;
                }
                if (string.IsNullOrEmpty(returnUrl) || returnUrl == "/")
                {
                    var rUser = new System.Security.Claims.ClaimsPrincipal(AuthenticationManager.AuthenticationResponseGrant.Identity);
                    if (rUser.IsInRole("Admin"))
                    {
                        return(RedirectToAction("WorkOrders", "Home"));
                    }
                    else if (rUser.IsInRole("Data Entry"))
                    {
                        return(RedirectToAction("WorkOrderSummary", "Home"));
                    }
                }
                return(RedirectToLocal(returnUrl));
            }

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Index()
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            bool isUser = currentUser.IsInRole("User");
            var  user   = await _userManager.GetUserAsync(User);

            return(View(user));
        }
 private DateTime?GetDiscardDateFromUserType(System.Security.Claims.ClaimsPrincipal user)
 {
     if (!user.Identity.IsAuthenticated)
     {
         return(DateTime.Now.AddDays(7));
     }
     if (user.IsInRole("premium"))
     {
         return(null);
     }
     return(DateTime.Now.AddYears(1));
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> Solved()
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            ViewData["Administrator"] = currentUser.IsInRole("Administrator");

            var puz = await _context.Puzzles.ToListAsync();

            var solved = puz.Where(s => s.Solved != null)
                         .OrderBy(t => t.Created)
                         .ToList();


            return(View(solved));
        }
Ejemplo n.º 10
0
        public ActionResult StoryDetail(int?id)
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            string currentUserName = this.User.Identity.Name;

            if (id == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            Story story = context_.Story.Find(id);

            if (story == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            if (story.isPublic == "Yes" || currentUser.IsInRole("Admin") || currentUserName == story.Publisher)
            {
                var imageblocks = context_.ImageBlock.Where(l => l.Story == story);
                story.ImageBlocks = imageblocks.OrderBy(l => l.ImageBlockIndex).Select(l => l).ToList <ImageBlock>();
                if (story.ImageBlocks == null)
                {
                    story.ImageBlocks = new List <ImageBlock>();
                    ImageBlock im = new ImageBlock();
                    im.ImageBlockIndex  = 0;//must add this,or cannot modify
                    im.ImageCaption     = "none";
                    im.ImageName        = "none";
                    im.ImagePath        = "none";
                    im.ImageDescription = "none";
                    story.ImageBlocks.Add(im);
                }


                var comments = context_.Comment.Where(l => l.Story == story);
                story.Comments = comments.OrderBy(l => l.ReviewTime).Select(l => l).ToList <Comment>();
                if (story.Comments == null)
                {
                    story.Comments = new List <Comment>();
                    Comment co = new Comment();
                    co.Content = "none";
                    story.Comments.Add(co);
                }
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            return(View(story));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> AdminProfile()
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            bool IsAdmin = currentUser.IsInRole("Admin");
            var  id      = _userManager.GetUserId(User); // Get user id:

            var user = await _userManager.FindByIdAsync(id);

            var adminProfileViewModel = new AdminProfileViewModel();

            adminProfileViewModel.Name        = user.UserName;
            adminProfileViewModel.AdminUserId = user.Id;
            adminProfileViewModel.Email       = user.Email;
            adminProfileViewModel.PhoneNumber = user.PhoneNumber;
            return(View(adminProfileViewModel));
        }
Ejemplo n.º 12
0
        public ActionResult getTournaments()
        {
            try
            {
                System.Security.Claims.ClaimsPrincipal currentUser = this.User;
                var  username    = User.Identities.First().Name;
                bool IsAdmin     = currentUser.IsInRole("Admin");
                var  tournaments = _context.Tournament.ToList();

                return(Json(new
                {
                    tournaments
                }));
            }
            catch (Exception ex)
            {
                // _logger.LogError(ex, "Error occured on update set");
                throw new NotImplementedException(ex.Message);
            }
        }
Ejemplo n.º 13
0
        public IActionResult Index()
        {
            if (!_signInManager.IsSignedIn(User))
            {
                return(Redirect("~/Account/LoginAdmin"));
            }
            else
            {
                System.Security.Claims.ClaimsPrincipal currentUser = User;
                var isAdmin = currentUser.IsInRole("admin");

                if (isAdmin)
                {
                    var model = _clientRepository.Find(x => x.Status == 'I' || x.Status == 'P' || x.Status == 'E');
                    return(View(model));
                }
            }

            return(Redirect("~/Account/LoginAdmin"));
        }
        public async Task <IActionResult> Index()
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            if (_signInManager.IsSignedIn(currentUser))
            {
                if (currentUser.IsInRole(Roles.Admin.ToString()))
                {
                    ICollection <Customer> Customers = await _customerService.GetAllAsync();

                    return(View(Customers));
                }
                else
                {
                    string   username = currentUser.Identity.Name;
                    Customer customer = _customerService.GetByUsername(username);

                    return(RedirectToAction("DetailCustomer", "Shop", new { id = customer.Id }));
                }
            }
            else
            {
                return(RedirectToAction("LoginFirst"));
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// check if a user is in the specific Role or not
 /// </summary>
 /// <param name="user">this user represent the securety claims in the current HttpContext</param>
 /// <returns>bool</returns>
 public bool checkRole(System.Security.Claims.ClaimsPrincipal user, string roleName)
 {
     return(user.IsInRole(roleName));
 }
 public bool CheckIfUserISPremiumUser(RoleManager <IdentityRole> roleManager, System.Security.Claims.ClaimsPrincipal user)
 {
     return(user.IsInRole("PremiumUser"));
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Extension to ClaimsPrincipal to allow checking for user roles within a context.
        /// </summary>
        /// <param name="cp">ClaimsPrincipal</param>
        /// <param name="context">User context (ie. subscriptionId)</param>
        /// <param name="role">Role</param>
        /// <returns>true if user is in role</returns>
        /// <example>
        /// user.IsInRole(mySubscriptionId, "SubscriptionAdmin");
        /// </example>
        public static bool IsInRole(this System.Security.Claims.ClaimsPrincipal cp, string context, string role)
        {
            string newRole = RoleFormatter(context, role);

            return(cp.IsInRole(newRole));
        }