Пример #1
0
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="userNode">XML for user</param>
    /// <param name="userIdFixed">NULL if ID is expected in the XML.  If non-NULL we will use the handed in user-id</param>
    private SiteUser(XmlNode userNode, string userIdFixed, SiteUserAuth?siteUserAuthFixed)
    {
        if (userNode.Name.ToLower() != "user")
        {
            AppDiagnostics.Assert(false, "Not a user");
            throw new Exception("Unexpected content - not user");
        }

        //If we have not been handed a user-id, then it must be in the XML
        if (string.IsNullOrEmpty(userIdFixed))
        {
            this.Id = userNode.Attributes["id"].Value;
        }
        else
        {
            this.Id = userIdFixed;
        }

        this.Name     = userNode.Attributes["name"].Value;
        this.SiteRole = userNode.Attributes["siteRole"].Value;

        this.LastLogin       = XmlHelper.GetAttributeDateTimeIfExists(userNode, "lastLogin");
        this.LastLoginAsText = XmlHelper.GetAttributeIfExists(userNode, "lastLogin", null);

        //Not all of the REST APIs return full name
        this.FullName = XmlHelper.GetAttributeIfExists(userNode, "fullName", "");

        this.SiteRoleParsed = ParseUserRole(this.SiteRole);
        AppDiagnostics.Assert(this.SiteRoleParsed != SiteUserRole.Unknown, "Unknown user role: " + this.SiteRole);


        //If we were not passed in an explicit user authentication, then it needs to be in the XML
        if (siteUserAuthFixed == null)
        {
            this.SiteAuthentication = userNode.Attributes["authSetting"].Value;

            this.SiteAuthenticationParsed = ParseUserAuthentication(this.SiteAuthentication);
            AppDiagnostics.Assert(this.SiteAuthenticationParsed != SiteUserAuth.Unknown, "Unknown user auth: " + this.SiteAuthenticationParsed);
        }
        else
        {
            //Use the explicitly passed in value
            this.SiteAuthenticationParsed = siteUserAuthFixed.Value;
            this.SiteAuthentication       = UserAuthenticationToString(this.SiteAuthenticationParsed);
        }


        this.IsSiteAdmin = ParseIsSiteAdmin(this.SiteRole);

        //=============================================================================
        //[2019-10-30] Currently Query User APIs do not return the user's email.
        //If the User Name is the email (as it is in Tableau Online) then grab that
        //=============================================================================
        string candidateEmail = this.Name;

        if (RegExHelper.IsEmail(candidateEmail))
        {
            this.Email = candidateEmail;
        }
    }
Пример #2
0
        public ActionResult CreateNewUser(CreateNewAreaUserDto model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var sur = new SiteUserRole
            {
                RoleId      = 3,
                SiteId      = model.AreaId,
                CreatedDate = DateTime.Now,
                User        = new User
                {
                    UserName    = model.UserName,
                    Password    = model.NationalCode,
                    Status      = true,
                    CreatedDate = DateTime.Now,
                    Person      = new Person
                    {
                        BirthDate    = DateTime.Now,
                        SexId        = 1,
                        CreatedDate  = DateTime.Now,
                        FirstName    = model.FirstName,
                        LastName     = model.LasttName,
                        NationalCode = model.NationalCode
                    }
                }
            };

            db.Set <SiteUserRole>().Add(sur);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Пример #3
0
 public static string MapRole(string siteId, SiteUserRole userRole)
 {
     if (SiteUserRole.Administrator == userRole)
     {
         return(siteId);
     }
     else
     {
         return(siteId + "_private_user");
     }
 }
Пример #4
0
 public void Create(SiteUserRole siteUserRole)
 {
     uow.Repository <SiteUserRole>().Create(siteUserRole);
     uow.SaveChanges();
 }
 private static async Task <string> ManageRolesAsync(UserService _userService, SaveSiteUserInput saveSiteUser,
                                                     ApplicationUser updatedUserDb, string role, SiteUserRole siteUserRole)
 {
     if (saveSiteUser.Roles != null && saveSiteUser.Roles.Contains(siteUserRole))
     {
         if (updatedUserDb != null)
         {
             if (updatedUserDb.Roles.Count(c => c == role) <= 0)
             {
                 updatedUserDb.AddClaim(new Claim(role, ""));
                 await _userService.SaveAsync(updatedUserDb);
             }
             return("user_updated");
         }
         else
         {
             return("no_user_found");
         }
     }
     else
     {
         var claim = updatedUserDb.Roles.FirstOrDefault(c => c == role);
         if (updatedUserDb != null && claim != null)
         {
             updatedUserDb.Roles.Remove(claim);
             await _userService.SaveAsync(updatedUserDb);
         }
     }
     return(String.Empty);
 }
Пример #6
0
        public ActionResult CreateNewEducationalCenter(EducationalCenterDefinitionDto model)
        {
            var areaId = WebUserInfo.SiteId;
            var stepNo = 1000;

            var newSiteId = db.Set <EducationalCenter>().Where(ec => ec.AreaId == areaId).OrderByDescending(ec => ec.CreatedDate).FirstOrDefault();

            if (newSiteId != null)
            {
                stepNo = Convert.ToInt32((newSiteId.Id.ToString()).Substring(6)) + 1;
            }

            var cis           = db.Set <CategoryItem>().Include("Category").Where(c => model.CategoryItemsIds.Contains(c.Id)).ToList();
            var cat           = cis.First().Category;
            var catName       = cat.Name;
            var catCode       = cat.Code;
            var userId        = WebUserInfo.UserId.ToString();
            var ecGeneratedId = EducationalCenterCodeGenetrator.GenerateNew(areaId, model.SexId, catCode, stepNo);

            var educationalCenter = new EducationalCenter
            {
                AreaId              = areaId,
                CertificateCode     = model.CertificateCode,
                SexId               = model.SexId,
                CreatedBy           = userId,
                MoassesFirstName    = model.MoassesFirstName,
                MoassesLastName     = model.MoassesLastName,
                MoassesNationalCode = model.MoassesNationalCode,
                ShiftId             = model.ShiftId,
                CategoryItems       = cis,
                Category            = catName,
                Site = new Site
                {
                    Id        = ecGeneratedId,
                    Name      = model.EducationalCenterName,
                    CreatedBy = userId
                }
            };

            db.Set <EducationalCenter>().Add(educationalCenter);
            db.SaveChanges();

            var sur = new SiteUserRole
            {
                User = new User
                {
                    Person = new Person
                    {
                        FirstName       = model.MoassesFirstName,
                        LastName        = model.MoassesLastName,
                        BirthDate       = DateTime.Now,
                        SexId           = 1,
                        BirthDateJalali = "1346",
                        NationalCode    = model.MoassesNationalCode,
                        CreatedBy       = WebUserInfo.UserId.ToString(),
                        CreatedDate     = DateTime.Now
                    },
                    UserName    = ecGeneratedId.ToString(),
                    Password    = model.MoassesNationalCode,
                    Status      = true,
                    CreatedBy   = WebUserInfo.UserId.ToString(),
                    CreatedDate = DateTime.Now,
                },
                RoleId      = 4,
                SiteId      = ecGeneratedId,
                CreatedDate = DateTime.Now,
                CreatedBy   = userId
            };

            db.Set <SiteUserRole>().Add(sur);

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }