Esempio n. 1
0
 /// <summary>
 /// Get roles from user. Use "GetLoggedUser()" to get "ApplicationUser"
 /// </summary>
 /// <param name="userID">Send "ApplicationUser.id" from method "GetLoggerUser()"</param>
 /// <returns></returns>
 public List <string> GetRolesFromUser(string userID, out string error)
 {
     error = null;
     try
     {
         UserManager UserManager = new GreeNova.DGNB.SystemSoftware.SecurityProvider.Managers.UserManager();
         var         roles       = UserManager.GetRoles(userID);
         return(roles.ToList());
     }
     catch (Exception ex)
     {
         error = "Could not retrive 'GetRolesFromUser'. Error:" + ex.Message + Environment.NewLine + ex.StackTrace;
         return(null);
     }
 }
Esempio n. 2
0
        public GreeNova.DGNB.SystemSoftware.SecurityProvider.Database.ApplicationUser GetUserByID(string userID, out string error)
        {
            error = null;
            try
            {
                UserManager UserManager = new GreeNova.DGNB.SystemSoftware.SecurityProvider.Managers.UserManager();

                GreeNova.DGNB.SystemSoftware.SecurityProvider.Database.ApplicationUser user = UserManager.FindById(userID);
                return(user);
            }
            catch (Exception ex)
            {
                error = "Could not retrive 'User'. Error:" + ex.Message + Environment.NewLine + ex.StackTrace;
                return(null);
            }
        }
Esempio n. 3
0
        public GreeNova.DGNB.SystemSoftware.SecurityProvider.Database.ApplicationUser GetUser(string name, out string error)
        {
            error = null;
            try
            {
                if (name == null)
                {
                    name = "*****@*****.**";
                }
                UserManager UserManager = new GreeNova.DGNB.SystemSoftware.SecurityProvider.Managers.UserManager();

                GreeNova.DGNB.SystemSoftware.SecurityProvider.Database.ApplicationUser user = UserManager.FindByName(name);
                return(user);
            }
            catch (Exception ex)
            {
                error = "Could not retrive 'GetLoggedUser'. Error:" + ex.Message + Environment.NewLine + ex.StackTrace;
                return(null);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Get logged user. Example:
 /// ApplicationUser loggedUser = helper.GetLoggedUser(RequestContext.Principal.Identity, out error);
 /// </summary>
 /// <param name="principal">use "RequestContext.Principal.Identity"</param>
 /// <returns></returns>
 public ApplicationUser GetLoggedUser(IIdentity principal, out string error)
 {
     error = null;
     try
     {
         UserManager UserManager = new GreeNova.DGNB.SystemSoftware.SecurityProvider.Managers.UserManager();
         if (principal.Name == null)
         {
             return(null);
         }
         GreeNova.DGNB.SystemSoftware.SecurityProvider.Database.ApplicationUser loggedUser = UserManager.FindByName(principal.Name);
         ApplicationUser usr = new ApplicationUser();
         usr.Id = loggedUser.Id;
         return(usr);
     }
     catch (Exception ex)
     {
         error = "Could not retrive 'GetLoggedUser'. Error:" + ex.Message + Environment.NewLine + ex.StackTrace;
         return(null);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Ultimate place to get logged info data
        /// </summary>
        /// <param name="principal"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public LoggedUserCompleteInfo GetLoggedUserAndLocalDBUser(IIdentity principal, bool loadRoles, out string error)
        {
            error = null;
            try
            {
                UserManager UserManager = new GreeNova.DGNB.SystemSoftware.SecurityProvider.Managers.UserManager();
                if (principal.Name == null)
                {
                    return(null);
                }
                GreeNova.DGNB.SystemSoftware.SecurityProvider.Database.ApplicationUser loggedUser = UserManager.FindByName(principal.Name);

                LoggedUserCompleteInfo loggedUserInfo = new LoggedUserCompleteInfo();
                loggedUserInfo.MainRole = "";
                loggedUserInfo.GreenNovaLoggedUser.UserName = loggedUser.UserName;
                if (loadRoles)
                {
                    List <string> roles = UserManager.GetRoles(loggedUser.Id).ToList();
                    loggedUserInfo.GreenNovaLoggedUser.Roles = roles;

                    PermissionManager permissionManager = new PermissionManager();
                    if (roles != null)
                    {
                        if (roles.Count > 0)
                        {
                            loggedUserInfo.MainRole = permissionManager.GetMainUserRole(roles);
                        }
                    }
                }

                loggedUserInfo.LoadLocalDBUser();

                return(loggedUserInfo);
            }
            catch (Exception ex)
            {
                error = "Could not retrive 'GetLoggedUser'. Error:" + ex.Message + Environment.NewLine + ex.StackTrace;
                return(null);
            }
        }