Example #1
0
        public ActionResult Login()
        {
            try
            {
                GetUserProfileObject PostDataArrived = CS.GetPostData <GetUserProfileObject>(this.Request);

                ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientSSO"];
                if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString))
                {
                    throw new Exception("ConnectionString not set");
                }

                if (PostDataArrived.IsSuperAdmin)
                {
                    UserRolesEnum ruolo = UserRolesEnum.Administrator;
                    PostDataArrived.UserRole = new UserRoleObject()
                    {
                        RoleId = (int)ruolo, Role = ruolo.ToString()
                    };
                }
                else
                {
                    connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"];
                    ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString);
                    PostDataArrived.UserRole = pw.GetRole(PostDataArrived);
                }

                Session[ProfileSession] = PostDataArrived;
                return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(PostDataArrived)));
            }
            catch (Exception ex)
            {
                return(CS.ReturnForJQuery(ex.Message));
            }
        }
 public UpdateUserDTO(string name, string email, UserRolesEnum role, string phoneNumber)
 {
     this.Name        = name;
     this.Email       = email;
     this.Role        = role;
     this.PhoneNumber = phoneNumber;
 }
        private IActionResult RedirectLoggedInUser(UserRolesEnum role)
        {
            switch (role)
            {
            case UserRolesEnum.Tenant:
                return(RedirectToAction("Requests", "Tenant"));

            case UserRolesEnum.Superintendent:
                return(RedirectToAction("Requests", "Superintendent"));

            case UserRolesEnum.Worker:
                return(RedirectToAction("Requests", "Worker"));

            case UserRolesEnum.Anonymous:
                break;

            case UserRolesEnum.Administrator:
                break;

            default:
                break;
            }



            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }
Example #4
0
 public UserClaimsService(string emailAddress, UserRolesEnum userRole = UserRolesEnum.Anonymous, string propCode = "", string unitNumber = "")
 {
     Login      = emailAddress;
     UserRole   = userRole;
     PropCode   = propCode;
     UnitNumber = unitNumber;
 }
Example #5
0
        public static IEnumerable <string> GetAllRolesByMaximumRole(UserRolesEnum role)
        {
            var result = new List <string>()
            {
                User
            };

            switch (role)
            {
            case UserRolesEnum.Admin:
                result.Add(Admin);
                result.Add(Moderator);
                break;

            case UserRolesEnum.Moderator:
                result.Add(Moderator);
                break;

            case UserRolesEnum.User:
                break;

            default:
                break;
            }
            return(result);
        }
Example #6
0
 public bool RemoveUserFromRole(string userId, UserRolesEnum roleName)
 {
     if (UserRepository.IsUserADemoUser(userId))
     {
         throw new ArgumentException("You can't change the roles of a demo user");
     }
     IdentityResult result = UserManager.RemoveFromRole(userId, roleName.ToString());
     return result.Succeeded;
 }
Example #7
0
        public override async Task <OperationResult> RegisterUser(UserRolesEnum userRole, string email, string password)
        {
            await Task.CompletedTask;

            _claims.Add(email, new UserClaimsService(email, UserRolesEnum.Anonymous, "", ""));
            return(new OperationResult()
            {
                Succeeded = true
            });
        }
Example #8
0
        public override async Task SetUserClaims(string email, UserRolesEnum userRole, string propCode, string unitNumber)
        {
            await Task.CompletedTask;

            if (!_claims.ContainsKey(email))
            {
                throw new Exception("User not logged in");
            }
            _claims[email] = new UserClaimsService(email, userRole, propCode, unitNumber);
        }
Example #9
0
        public List<ApplicationUser> UsersNotInRole(UserRolesEnum roleName)
        {
            List<ApplicationUser> resultList = new List<ApplicationUser>();
            List<ApplicationUser> list = UserManager.Users.ToList();

            foreach (ApplicationUser user in list)
            {
                if (!IsUserInRole(user.Id, roleName.ToString()))
                {
                    resultList.Add(user);
                }
            }

            return resultList;
        }
Example #10
0
        public List<ApplicationUser> UsersInRole(UserRolesEnum roleName)
        {
            List<ApplicationUser> resultList = new List<ApplicationUser>();
            List<ApplicationUser> list = UserManager.Users.ToList();

            foreach (ApplicationUser user in list)
            {
                IList<string> currentRoleList = UserManager.GetRoles(user.Id);
                if (IsUserInRole(user.Id, roleName.ToString()))
                {
                    resultList.Add(user);
                }
            }

            return resultList;
        }
        public UserRoleObject GetRole(GetUserProfileObject PostDataArrived)
        {
            try
            {
                if (PostDataArrived == null || string.IsNullOrEmpty(PostDataArrived.UserCode))
                {
                    throw new Exception("Input Error");
                }

                string sqlquery = string.Format("Select * from UserRoles where UserCode='{0}'", PostDataArrived.UserCode.Replace("'", "''"));

                Sqlconn.Open();
                try
                {
                    DataTable dtres = new DataTable();
                    using (SqlCommand comm = new SqlCommand(sqlquery, Sqlconn))
                    {
                        using (SqlDataAdapter da = new SqlDataAdapter(comm))
                        {
                            da.Fill(dtres);
                        }
                    }
                    UserRolesEnum ruolo = UserRolesEnum.User;
                    if (dtres != null && dtres.Rows.Count > 0)
                    {
                        int RoleCode = Convert.ToInt32(dtres.Rows[0]["RoleId"].ToString());
                        ruolo = (UserRolesEnum)RoleCode;
                    }

                    return(new UserRoleObject()
                    {
                        RoleId = (int)ruolo, Role = ruolo.ToString()
                    });
                }
                catch (Exception) { throw; }
                finally
                {
                    Sqlconn.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw new Exception(string.Format(ErrorOccuredMess, ex.Message));
            }
        }
        public override async Task SetUserClaims(string email, UserRolesEnum userRole, string propCode, string unitNumber)
        {
            B2CCustomAttributeHelper helper = new B2CCustomAttributeHelper(_config.B2cExtensionAppClientId);
            string userRoleAttributeName    = helper.GetCompleteAttributeName("userrole");
            string propCodeAttributeName    = helper.GetCompleteAttributeName("PropertyCode");


            IDictionary <string, object> extensionInstance = new Dictionary <string, object>();

            extensionInstance.Add(helper.GetCompleteAttributeName("userrole"), userRole.ToString( ));
            if (!string.IsNullOrEmpty(propCode))
            {
                extensionInstance.Add(helper.GetCompleteAttributeName("PropertyCode"), propCode);
            }
            if (!string.IsNullOrEmpty(unitNumber))
            {
                extensionInstance.Add(helper.GetCompleteAttributeName("UnitNumber"), unitNumber);
            }

            var userToUpdate = new User
            {
                AdditionalData = extensionInstance
            };

            var result = await _graphClient.Users
                         .Request()
                         .Filter($"identities/any(c:c/issuerAssignedId eq '{IntLoggedUser.Login}' and c/issuer eq '{_config.TenantId}')")
                         .Select(e => new
            {
                e.DisplayName,
                e.Id,
                e.Identities
            })
                         .GetAsync();

            var user = result.CurrentPage.FirstOrDefault();

            ObjectIdentity objIdentity = user?.Identities.FirstOrDefault();

            if (objIdentity != null && objIdentity.IssuerAssignedId == IntLoggedUser.Login)
            {
                await _graphClient.Users[user.Id]
                .Request()
                .UpdateAsync(userToUpdate);
            }
        }
        public override async Task SetUserClaims(string email, UserRolesEnum userRole, string propCode, string unitNumber)
        {
            var user = await _userManager.FindByEmailAsync(email);

            var roleCheck = await _roleManager.RoleExistsAsync(userRole.ToString());

            if (!roleCheck)
            {
                //create the roles and seed them to the database
                var roleResult = await _roleManager.CreateAsync(new IdentityRole(userRole.ToString()));
            }
            await _userManager.RemoveFromRoleAsync(user, UserRolesEnum.Anonymous.ToString());

            await _userManager.AddToRoleAsync(user, userRole.ToString());

            await _securitySignInService.SignInAsync(user, isPersistent : false);

            switch (userRole)
            {
            case UserRolesEnum.Anonymous:
                break;

            case UserRolesEnum.Tenant:
                await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(SecurityClaims.PropertyCode.ToString(), propCode));

                await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(SecurityClaims.UnitNumber.ToString(), unitNumber));

                await _userManager.UpdateAsync(user);

                break;

            case UserRolesEnum.Superintendent:
                await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(SecurityClaims.PropertyCode.ToString(), propCode));

                await _userManager.UpdateAsync(user);

                break;

            case UserRolesEnum.Administrator:
                break;

            case UserRolesEnum.Worker:
                break;
            }
        }
        public override async Task <OperationResult> RegisterUser(UserRolesEnum userRole, string email, string password)
        {
            var user = new ApplicationUser {
                UserName = email, Email = email
            };
            var result = await _userManager.CreateAsync(user, password);

            //userRole = UserRolesEnum.Anonymous; // replace for now
            if (result.Succeeded)
            {
                var roleCheck = await _roleManager.RoleExistsAsync(UserRolesEnum.Anonymous.ToString());

                if (!roleCheck)
                {
                    //create the roles and seed them to the database
                    var roleResult = await _roleManager.CreateAsync(new IdentityRole(UserRolesEnum.Anonymous.ToString()));
                }

                user = await _userManager.FindByEmailAsync(email);

                await _userManager.AddToRoleAsync(user, UserRolesEnum.Anonymous.ToString());


                _logger.LogInformation("User created a new account with password.");


                await _securitySignInService.SignInAsync(user, isPersistent : false);

                _logger.LogInformation("User created a new account with password.");
                return(new OperationResult()
                {
                    Succeeded = true
                });
            }

            return(new OperationResult()
            {
                Succeeded = false,
                ErrorsValueTuples = result.Errors.Select(x => new Tuple <string, string>(x.Code, x.Description)).ToList()
            });
        }
        public override async Task <UserClaimsService> GetUserClaims(string emailLogin)
        {
            await Task.CompletedTask;


            if (string.IsNullOrEmpty(emailLogin))
            {
                //throw new NullReferenceException(nameof(emailClaim));
                IntLoggedUser = new UserClaimsService("",
                                                      UserRolesEnum.Anonymous,
                                                      "",
                                                      "");
                return(IntLoggedUser);
            }

            var           userRoleClaim = _claims.FirstOrDefault(x => x.Type == "extension_userrole");
            UserRolesEnum userRole      = UserRolesEnum.Anonymous;

            if (userRoleClaim != null)
            {
                Enum.TryParse(userRoleClaim.Value, out userRole);
            }


            IntLoggedUser = new UserClaimsService(emailLogin,
                                                  userRole,
                                                  "",
                                                  "");

            switch (userRole)
            {
            case UserRolesEnum.Anonymous:
                break;

            case UserRolesEnum.Tenant:
                IntLoggedUser = new UserClaimsService(emailLogin,
                                                      userRole,
                                                      _claims.FirstOrDefault(x => x.Type == "extension_PropertyCode")?.Value,
                                                      _claims.FirstOrDefault(x => x.Type == "extension_UnitNumber")?.Value);

                break;

            case UserRolesEnum.Superintendent:
                IntLoggedUser = new UserClaimsService(emailLogin,
                                                      userRole,
                                                      _claims.FirstOrDefault(x => x.Type == "extension_PropertyCode")?.Value,
                                                      "");

                break;

            case UserRolesEnum.Administrator:
                break;

            case UserRolesEnum.Worker:

                break;
            }



            return(IntLoggedUser);
        }
Example #16
0
 public DefaultRole(UserRolesEnum role)
 {
     this.Role = role;
 }
        public List <GetUserProfileObject> GetUserList(string SingleSignOnConf)
        {
            List <GetUserProfileObject> utentiSSON = GetSingleSignONUsers(SingleSignOnConf);

            try
            {
                string sqlquery = string.Format("Select * from UserRoles");
                Sqlconn.Open();
                try
                {
                    DataTable dtres = new DataTable();
                    using (SqlCommand comm = new SqlCommand(sqlquery, Sqlconn))
                    {
                        using (SqlDataAdapter da = new SqlDataAdapter(comm))
                        {
                            da.Fill(dtres);
                        }
                    }

                    foreach (DataRow userrow in dtres.Rows)
                    {
                        GetUserProfileObject user = utentiSSON.Find(u => u.UserCode == userrow["UserCode"].ToString());
                        if (user == null)
                        {
                            DeleteUserforSynk(userrow["UserCode"].ToString());
                            continue;
                        }
                        UserRolesEnum ruolo = UserRolesEnum.User;
                        if (user.IsSuperAdmin)
                        {
                            ruolo = UserRolesEnum.Administrator;
                        }
                        else
                        {
                            ruolo = (UserRolesEnum)Convert.ToInt32(userrow["RoleId"].ToString());
                        }

                        user.UserRole = new UserRoleObject()
                        {
                            RoleId = (int)ruolo, Role = ruolo.ToString()
                        };
                    }
                    utentiSSON.FindAll(u => u.UserRole == null).ForEach(u =>
                    {
                        UserRolesEnum ruolo = UserRolesEnum.User;
                        if (u.IsSuperAdmin)
                        {
                            ruolo = UserRolesEnum.Administrator;
                        }
                        u.UserRole = new UserRoleObject()
                        {
                            RoleId = (int)ruolo, Role = ruolo.ToString()
                        };
                    });

                    return(utentiSSON);
                }
                catch (Exception) { throw; }
                finally
                {
                    Sqlconn.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw new Exception(string.Format(ErrorOccuredMess, ex.Message));
            }
        }
 public abstract Task <OperationResult> RegisterUser(UserRolesEnum userRole, string email, string password);
 public abstract Task SetUserClaims(string email, UserRolesEnum userRole, string propCode, string userNumber);
 public override Task <OperationResult> RegisterUser(UserRolesEnum userRole, string email, string password)
 {
     throw new NotImplementedException();
 }
Example #21
0
 public bool IsUserInRole(string userId, UserRolesEnum roleName) => UserManager.IsInRole(userId, roleName.ToString());