Esempio n. 1
0
 public CProfile()
 {
     PlayerName = String.Empty;
     Difficulty = EGameDifficulty.TR_CONFIG_EASY;
     UserRole   = EUserRole.TR_USERROLE_NORMAL;
     Active     = EOffOn.TR_CONFIG_ON;
 }
        public async Task <IHttpActionResult> Approve(int id, [FromBody] ActionNoteRequest actionNoteRequest)
        {
            try
            {
                EUserRole     userRole = GetUserAuth().UserRole;
                UserModel     getUser  = GetUserAuth();
                EStatusCredit statusCredit;

                if (userRole == EUserRole.User)
                {
                    statusCredit = EStatusCredit.AR;
                }
                else if (userRole == EUserRole.AR)
                {
                    statusCredit = EStatusCredit.CashBank;
                }
                else if (userRole == EUserRole.CashBank)
                {
                    statusCredit = EStatusCredit.FBS;
                }
                else if (userRole == EUserRole.FBS)
                {
                    statusCredit = EStatusCredit.ManagementRisk;
                }
                else if (userRole == EUserRole.ManagementRisk)
                {
                    statusCredit = EStatusCredit.KomiteCredit;
                }
                else
                {
                    statusCredit = EStatusCredit.Completed;
                }


                CreditApproval creditApproval = await _creditApprovalRepository.UpdateStatus(id, statusCredit, true);

                if (creditApproval == null)
                {
                    return(new HttpJsonApiResult <string>("Not Found", Request, HttpStatusCode.NotFound));
                }

                TrCaActionNote trCaActionNote = await _trCaActionNoteRepository.Create(new TrCaActionNote()
                {
                    CreditApprovalId = creditApproval.Id,
                    ActionNote       = actionNoteRequest.ActionNote,
                    ActionType       = 1,
                    ActionBy         = getUser.Id
                });

                //send email here
                return(new HttpJsonApiResult <CreditApprovalModel>(new CreditApprovalModel(creditApproval),
                                                                   Request, HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(new HttpJsonApiResult <string>(
                           "Internal Server Error", Request, HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 3
0
 public Command(ECommandType commandType, string commandMessage, EUserRole minimalAccessRole,
                string description)
 {
     CommandType       = commandType;
     CommandMessage    = commandMessage;
     MinimalAccessRole = minimalAccessRole;
     Description       = description;
 }
 /// <summary>
 /// Check if the authorization header has a specific role
 /// </summary>
 /// <param name="role"></param>
 /// <returns></returns>
 public AmazingRequestContext HasRole(EUserRole role)
 {
     if (this.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Role)?.Value != role.ToString())
     {
         throw new AmazingException(HttpStatusCode.Unauthorized, $"Unauthorized");
     }
     return(this);
 }
Esempio n. 5
0
 public UserViewModel(User user)
 {
     Id         = user.Id;
     FirstName  = user.FirstName;
     MiddleName = user.MiddleName;
     LastName   = user.LastName;
     Email      = user.Email;
     Role       = user.Role;
 }
Esempio n. 6
0
 public User(string name, string email, string userName, string password, EUserRole role)
 {
     Name     = name;
     Email    = email;
     UserName = userName;
     Password = password;
     Role     = role;
     Articles = new List <Article>();
     Videos   = new List <Video>();
 }
Esempio n. 7
0
 /// <summary>
 ///  Construtor que recebe os atributos do Objeto User a ser criado
 /// </summary>
 /// <param name="email">E-mail do usuário</param>
 /// <param name="password">Senha do usuário</param>
 /// <param name="name">Nome do usuário</param>
 /// <param name="userRole">Perfil do usuário</param>
 public CreateUserCommand(string email, string password, string name, EUserRole userRole)
 {
     this.UserId     = Guid.NewGuid();
     this.Email      = email;
     this.Password   = password;
     this.Name       = name;
     this.UserRole   = userRole;
     this.CreatedOn  = DateTime.Now;
     this.ModifiedOn = DateTime.Now;
     this.UserStatus = EUserStatus.Active;
     this.ApiKey     = Guid.NewGuid();
 }
Esempio n. 8
0
        public static void SetUserRoleProfile(Guid profileID, EUserRole option)
        {
            if (!IsProfileIDValid(profileID))
            {
                return;
            }
            //Only allow the change of TR_USERROLE_GUEST, TR_USERROLE_NORMAL and TR_USERROLE_ADMIN
            const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL | EUserRole.TR_USERROLE_ADMIN);

            option &= mask;
            _Profiles[profileID].UserRole = (_Profiles[profileID].UserRole & ~mask) | option;
        }
Esempio n. 9
0
        public async Task <AnswerBase> GetAppUserAsync(EUserRole role, int id = 0, string email = null)
        {
            if (role == EUserRole.Non)
            {
                return new AnswerFail
                       {
                           Reason = "Role must be or 'student' or 'prepod' or 'admin'"
                       }
            }
            ;
            if (id == 0 && email == null)
            {
                return new AnswerFail
                       {
                           Reason = "You must specify at least one of the 'id' or 'email' arguments"
                       }
            }
            ;
            if (email == null)
            {
                var user = await GetAppUserByIdAsync(role, id);

                if (user == null)
                {
                    return new AnswerFail
                           {
                               Reason = "Such a user is not registered in the system"
                           }
                }
                ;
                return(new AnswerAppUser {
                    AppUser = user
                });
            }
            else
            {
                var user = await GetAppUserByEmailAsync(role, email);

                if (user == null)
                {
                    return new AnswerFail
                           {
                               Reason = "Such a user is not registered in the system"
                           }
                }
                ;
                return(new AnswerAppUser {
                    AppUser = user
                });
            };
        }
Esempio n. 10
0
 public async Task <IActionResult> Get(EUserRole role)
 {
     try
     {
         return(Ok(await _appUsers.GetAppUsersAsync(role)));
     }
     catch (Exception ex)
     {
         return(Ok(new AnswerFail
         {
             Reason = ex.Message
         }));
     }
 }
Esempio n. 11
0
        private async Task <ApplicationUser> CreateUser(EUserRole userRole)
        {
            var email   = Guid.NewGuid() + "@dataexpertsgroup.com";
            var appUser = new ApplicationUser()
            {
                Email       = email,
                FirstName   = "First",
                LastName    = "Last",
                HubQuota    = 5,
                InviteQuota = 6,
                UserName    = "******",
                UserRole    = userRole
            };

            await _repositoryManager.CreateUserAsync(appUser, null, CancellationToken.None);

            return(appUser);
        }
        public string GenerateToken(string userName, EUserRole userRole)
        {
            var now    = DateTime.UtcNow;
            var claims = new List <Claim>()
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, userName),
                new Claim(ClaimsIdentity.DefaultRoleClaimType, userRole.ToString()),
            };
            var identity = new ClaimsIdentity(claims, "Token");

            var token = new JwtSecurityToken(_opts.JwtIssuer,
                                             _opts.JwtAudience,
                                             identity.Claims,
                                             now,
                                             now.AddMinutes(_opts.JwtLifetimeMins),
                                             new SigningCredentials(_opts.PrivateKey, SecurityAlgorithms.RsaSha256));

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
Esempio n. 13
0
        public static void SetUserRole(Guid profileId, int userRole)
        {
            CProfile profile = CProfiles.GetProfile(profileId);

            if (profile == null)
            {
                throw new ArgumentException("Invalid profileId");
            }

            var option = (EUserRole)userRole;

            //Only allow the change of all options exept TR_USERROLE_GUEST and TR_USERROLE_NORMAL
            const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL);

            option &= ~mask;

            profile.UserRole = (profile.UserRole & mask) | option;

            CProfiles.EditProfile(profile);
            CProfiles.Update();
            CProfiles.SaveProfiles();
        }
 public UserAccessAttribute(EUserRole userRole)
 {
     UserRole = userRole;
 }
Esempio n. 15
0
 private void Add(string command, ECommandType commandType, EUserRole minimalUserAccessRole, string description)
 {
     _commands.Add(command, new Command(commandType, command, minimalUserAccessRole, description));
 }
 /// <summary>
 /// Construtor que recebe os atributos do Objeto User a ser atualizado
 /// </summary>
 /// <param name="userId">ID do usuário</param>
 /// <param name="email">E-mail do usuário</param>
 /// <param name="password">Senha do usuário</param>
 /// <param name="name">Nome do usuário</param>
 /// <param name="userRole">Perfil do usuário</param>
 public UpdateUserCommand(Guid userId, string email, string password, string name, EUserRole userRole)
 {
     this.UserId     = userId;
     this.Email      = email;
     this.Password   = password;
     this.Name       = name;
     this.UserRole   = userRole;
     this.CreatedOn  = DateTime.Now;
     this.UserStatus = EUserStatus.Active;
 }
Esempio n. 17
0
        public static bool SendProfileData(SProfileData profile)
        {
            CProfile newProfile;
            CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId);

            if (existingProfile != null)
            {
                newProfile = new CProfile
                {
                    ID         = existingProfile.ID,
                    FilePath   = existingProfile.FilePath,
                    Active     = existingProfile.Active,
                    Avatar     = existingProfile.Avatar,
                    Difficulty = existingProfile.Difficulty,
                    UserRole   = existingProfile.UserRole,
                    PlayerName = existingProfile.PlayerName
                };
            }
            else
            {
                newProfile = new CProfile
                {
                    Active   = EOffOn.TR_CONFIG_ON,
                    UserRole = EUserRole.TR_USERROLE_NORMAL
                };
            }

            if (profile.Avatar != null)
            {
                newProfile.Avatar = _AddAvatar(profile.Avatar);
            }
            else if (newProfile.Avatar == null || newProfile.Avatar.ID == -1)
            {
                newProfile.Avatar = CProfiles.GetAvatars().First();

                /*CAvatar avatar = new CAvatar(-1);
                 * avatar.LoadFromFile("Profiles\\Avatar_f.png");
                 * CProfiles.AddAvatar(avatar);
                 * newProfile.Avatar = avatar;*/
            }

            if (!string.IsNullOrEmpty(profile.PlayerName))
            {
                newProfile.PlayerName = profile.PlayerName;
            }
            else if (!string.IsNullOrEmpty(newProfile.PlayerName))
            {
                newProfile.PlayerName = "DummyName";
            }

            if (profile.Difficulty >= 0 && profile.Difficulty <= 2)
            {
                newProfile.Difficulty = (EGameDifficulty)profile.Difficulty;
            }

            if (profile.Type >= 0 && profile.Type <= 1)
            {
                EUserRole option = profile.Type == 0 ? EUserRole.TR_USERROLE_GUEST : EUserRole.TR_USERROLE_NORMAL;
                //Only allow the change of TR_USERROLE_GUEST and TR_USERROLE_NORMAL
                const EUserRole mask = EUserRole.TR_USERROLE_NORMAL;
                newProfile.UserRole = (newProfile.UserRole & mask) | option;
            }

            if (!string.IsNullOrEmpty(profile.Password))
            {
                if (profile.Password == "***__CLEAR_PASSWORD__***")
                {
                    newProfile.PasswordSalt = null;
                    newProfile.PasswordHash = null;
                }
                else
                {
                    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                    byte[] buffer = new byte[32];
                    rng.GetNonZeroBytes(buffer);
                    byte[] salt           = buffer;
                    byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(profile.Password), salt);

                    newProfile.PasswordSalt = salt;
                    newProfile.PasswordHash = hashedPassword;
                }
            }

            if (existingProfile != null)
            {
                CProfiles.EditProfile(newProfile);
                CProfiles.Update();
                CProfiles.SaveProfiles();
            }
            else
            {
                CProfiles.AddProfile(newProfile);
            }

            return(true);
        }
Esempio n. 18
0
 public async Task <AnswerBase> GetAppUsersAsync(EUserRole role)
 => (role) switch
 {
Esempio n. 19
0
 public static string GetName(this EUserRole role)
 {
     return(Enum.GetName(typeof(EUserRole), role));
 }