Esempio n. 1
0
        public async Task <IActionResult> ChangeRole(ChangeRoleRequest request, CancellationToken cancellationToken)
        {
            await _identityService.ChangeRole(new ChangeRole.Request {
                UserId  = request.UserId,
                NewRole = request.NewRole
            }, cancellationToken);

            return(Ok());
        }
Esempio n. 2
0
        public ActionResult ResendInvite(string userData)
        {
            int nUsers                 = 0;
            int existActive            = 0;
            int accountId              = this.Identity.ToAccountID();
            ChangeRoleRequest request  = JsonConvert.DeserializeObject <ChangeRoleRequest>(userData);
            string            filename = EmailTemplate.ResendInvite.ToString() + ".txt";

            for (int i = 0; i < request.UserID.Count(); i++)
            {
                GetUserResponse response = userService.GetUser(new GetUserRequest(request.UserID[i]));
                if (string.IsNullOrEmpty(response.User.Password) && response.User.Status == 2)
                {
                    AccountSubscriptionData userSubscription = userService.GetSubscriptionData(accountId);
                    if (userSubscription.Limit.HasValue)
                    {
                        int usercount = userService.GetActiveUserIds(accountId, request.UserID);
                        if (usercount > userSubscription.Limit)
                        {
                            userService.UserLimitEmailNotification(accountId);
                            throw new UnsupportedOperationException("[|Maximum number of Users reached. Please contact Help Desk for assistance at [email protected].|]");
                        }
                    }

                    var name = response.User.FirstName + " " + response.User.LastName;
                    SendEmail(response.User.UserID.ToString(), response.User.AccountID.ToString(), response.User.PrimaryEmail, name, filename, this.Identity.ToAccountPrimaryEmail(), "ResendInvite");
                    nUsers++;
                }
                else
                {
                    existActive = 1;
                }
            }
            if (nUsers > 0)
            {
                if (existActive != 0)
                {
                    return(Json(new
                    {
                        success = true,
                        response = "[|Email successfully sent to|] " + nUsers + "[|User(s)|]" + "</br>" + "[|Email can not be sent to Active User(s)|]"
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        success = true,
                        response = "[|Email successfully sent to|] " + nUsers + " [|User(s)|]"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                throw new UnsupportedOperationException("[|Please select Unregistered User(s)|]");
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> ChangeRole(
            [FromServices] IChangeRoleUseCase changeRoleUseCase,
            [FromServices] ChangeRolePresenter changeRolePresenter,
            [FromBody] ChangeRoleRequest input)
        {
            await changeRoleUseCase.Execute(new ChangeRoleInput(input.UserId, input.RolesId));

            return(changeRolePresenter.ViewModel);
        }
Esempio n. 4
0
        public ActionResult UpdateUserRole(string userData)
        {
            ChangeRoleRequest request = JsonConvert.DeserializeObject <ChangeRoleRequest>(userData);

            request.AccountId = this.Identity.ToAccountID();
            userService.ChangeRole(request);
            InsertProfileAudit(request.UserID, UserAuditType.ProfileUpdate, null, this.Identity.ToUserID());
            return(Json(new
            {
                success = true,
                response = ""
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public void ChangeRole_ChangeUserRole_Failure()
        {
            int[]             user = new int[] { 1, 2, 61 };
            byte              role = 3;
            ChangeRoleRequest req  = new ChangeRoleRequest();

            req.RoleID = role;
            req.UserID = user;
            mockUserRepository.Setup(cr => cr.ChangeRole(It.IsAny <short>(), It.IsAny <int[]>())).Verifiable();
            ChangeRoleResponse res = userService.ChangeRole(req);

            mockRepository.VerifyAll();
            Assert.AreEqual(res.Exception, null);
        }
Esempio n. 6
0
        public async Task <IActionResult> ChangeRole(int id, ChangeRoleRequest request)
        {
            try
            {
                var result = await _teamService.ChangeUserRole(id, request.UserId, request.Role);

                return(Ok(new BoolResponse {
                    Success = result
                }));
            }
            catch (UnauthorizedAccessException)
            {
                return(Forbid());
            }
        }
        public HttpResponseMessage ChangeRole([FromBody] ChangeRoleRequest request)
        {
            var response = new ChangeRoleResponse();

            try
            {
                var token = Token.Get(request.Token);
                if (token == null)
                {
                    response.IsTokenTimeout = true;
                }
                else
                {
                    if (AccountBUS.CheckRole3(token.MaNV))
                    {
                        response.Data = true;
                        if (request.IsUp)
                        {
                            var temp = NhanVienRepository.GetInstance().GetUserById(token.MaNV);
                            if (temp != null)
                            {
                                token.CapPQ = 3;
                                token.MaCN  = temp.MaCN;
                            }
                            else
                            {
                                response.IsError = true;
                            }
                        }
                        else
                        {
                            token.CapPQ = 2;
                            token.MaCN  = request.AgencyId;
                        }
                    }
                }
            }
            catch
            {
                response.IsError = true;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Esempio n. 8
0
        public static async Task SeedEssentialsAsync(IMediator mediator, IIdentityService userService, RoleManager <IdentityRole> roleManager)
        {
            // Seeding roles
            foreach (var role in Enum.GetNames(typeof(Roles)))
            {
                if (!await roleManager.RoleExistsAsync(role))
                {
                    await roleManager.CreateAsync(new IdentityRole(role));
                }
            }

            var defaultAdminRegCmd = new UserRegistrationCommand()
            {
                FirstName = "Default",
                LastName  = "Admin",
                Password  = "******",
                UserName  = "******"
            };

            // Seeding default admin
            await mediator.Send(defaultAdminRegCmd);

            var changeRoleRequest = new ChangeRoleRequest()
            {
                Role     = Roles.Admin.ToString(),
                UserName = defaultAdminRegCmd.UserName
            };

            // Adding Admin role
            await userService.ChangeRoleAsync(changeRoleRequest, RoleActions.Add);

            var defaultReaderRegCmd = new UserRegistrationCommand()
            {
                FirstName = "Default",
                LastName  = "Reader",
                Password  = "******",
                UserName  = "******"
            };

            // Seeding default user
            await mediator.Send(defaultReaderRegCmd);
        }
Esempio n. 9
0
        public async Task <RequestResult> ChangeRoleAsync(ChangeRoleRequest request, RoleActions action)
        {
            var user = await _userManager.FindByNameAsync(request.UserName);

            if (user == null)
            {
                return(RequestResult.Fail(RequestError.NotFound, $"No account registred with username {request.UserName}"));
            }

            // Checking if requested role exists
            var role = Enum.GetNames(typeof(Roles)).FirstOrDefault(r => string.Equals(r, request.Role, StringComparison.OrdinalIgnoreCase));

            if (role == null)
            {
                return(RequestResult.Fail(RequestError.NotFound, $"Role {request.UserName} not found"));
            }

            switch (action)
            {
            case RoleActions.Add:
                if (await _userManager.IsInRoleAsync(user, role))
                {
                    return(RequestResult.Fail(RequestError.AlreadyExists, $"User {request.UserName} already has role {request.Role}"));
                }

                await _userManager.AddToRoleAsync(user, role);

                break;

            case RoleActions.Remove:
                if (!await _userManager.IsInRoleAsync(user, role))
                {
                    return(RequestResult.Fail(RequestError.NotFound, $"User {request.UserName} currently has no role {request.Role}"));
                }

                await _userManager.RemoveFromRoleAsync(user, role);

                break;
            }

            return(RequestResult.Success());
        }
Esempio n. 10
0
        public async Task <ActionResult> RemoveRole(ChangeRoleRequest request)
        {
            var result = await _userService.ChangeRoleAsync(request, RoleActions.Remove);

            return(result.Succeeded ? NoContent() : (ActionResult)BadRequest(result.ErrorsToString()));
        }
 public async Task <IActionResult> ChangeRole(ChangeRoleRequest request, [FromServices] IHandler <ChangeRoleRequest, ObjectResult> handler)
 {
     return(await handler.Handle(request));
 }