Esempio n. 1
0
        public async Task <IUserContext> GetCurrentUser(CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var context = _httpContextAccessor.HttpContext;

            if (context == null)
            {
                return(null);
            }
            var userId = context.User.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                return(null);
            }
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(null);
            }

            return(new UserContext(user));
        }
Esempio n. 2
0
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            var sub  = context.Subject.GetSubjectId();
            var user = await _userManager.FindByIdAsync(sub);

            var principal = await _claimsFactory.CreateAsync(user);

            context.AddFilteredClaims(principal.Claims);
        }
Esempio n. 3
0
        public async Task <IActionResult> Details(int id)
        {
            var project = await _repo.Get(id);

            var model    = _mapper.Map <Project, ProjectViewModel>(project);
            var property = await _propertyrepo.Get(project.PropertyId);

            var propertyOwner = await _siteUserManager.FindByIdAsync(project.PropertyOwnerId.ToString());

            var draughtsman = await _siteUserManager.FindByIdAsync(project.DraughtsmanId.ToString());

            //string siteid = "1732d901-82c3-4c48-9e02-3049c8ea2738";
            ProjectDetailsViewModel projectDetails = new ProjectDetailsViewModel
            {
                ProjectId                  = project.ProjectId,
                ProjectName                = project.ProjectName,
                ProjectDescription         = project.ProjectDescription,
                MunicipalRefNo             = project.MunicipalRefNo,
                DateofSubmission           = project.DateofSubmission,
                MunicipalAssessmentOfficer = project.MunicipalAssessmentOfficer,
                AssessmentOfficerEmail     = project.AssessmentOfficerEmail,
                AssessmentOfficerContactNo = project.AssessmentOfficerContactNo,
                DateCreated                = project.DateCreated,
                DateModified               = project.DateModified,
                PropertyId                 = project.PropertyId,
                DraughtsmanId              = project.DraughtsmanId,
                ProjectStateId             = project.ProjectStateId,
                SiteId = property.SiteId,

                PropertyName      = property.PropertyName,
                PropertyAddress   = property.PropertyAddress,
                PropertyERF_LotNo = property.PropertyERF_LotNo,
                IsComplex         = property.IsComplex,
                IsEstate          = property.IsEstate,
                Complex_Estate_No = property.Complex_Estate_No,
                PropertySGNo      = property.PropertySGNo,

                PropertyOwnerFirstName = propertyOwner.FirstName,
                PropertyOwnerLastName  = propertyOwner.LastName,
                PropertyOwnerEmail     = propertyOwner.Email,
                // PropertyOwnerContactNo = propertyOwner.PhoneNumber,

                DraughtsmanFirstName = draughtsman.FirstName,
                DraughtsmanLastName  = draughtsman.LastName,
                DraughtsmanEmail     = draughtsman.Email,
                DraughtsmanContactNo = draughtsman.PhoneNumber,
            };



            //Client or Property Owner Details
            //Draughtman Details

            // var model = _mapper.Map<Project, ProjectViewModel>(project);
            return(View(projectDetails));
        }
Esempio n. 4
0
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            var sub  = context.Subject.GetSubjectId();
            var user = await _userManager.FindByIdAsync(sub);

            var principal = await _claimsFactory.CreateAsync(user);

            var filtered = _claimsProcessor.ProcessClaims(context, principal.Claims, user);

            context.IssuedClaims.AddRange(filtered);
        }
        public async Task <IActionResult> Index()
        {
            var allProperties = await _repo.GetAll();

            var tb_property = allProperties.ToList();


            var siteId            = User.GetUserSiteIdAsGuid();
            var propertyOwnerRole = await _appRoleRepo.GetPropertyOwnerRoleId(siteId);

            var propertyOwnerRoleId = propertyOwnerRole.Id;
            var propertyOwners      = await _appUserRoleRepo.GetAllPropertyOwners(propertyOwnerRoleId);

            var propertyOwnersList = propertyOwners.ToList();

            var propertyList = new List <PropertyViewModel> {
            };

            //CREATE A PROPERTIES VIEWMODEL TO INCLUDE ALL THE OWNERS HERE
            foreach (var property in tb_property)
            {
                PropertyViewModel PropertywithOwner = new PropertyViewModel
                {
                    PropertyId        = property.PropertyId,
                    PropertyName      = property.PropertyName,
                    PropertySGNo      = property.PropertySGNo,
                    PropertyAddress   = property.PropertyAddress,
                    PropertyERF_LotNo = property.PropertyERF_LotNo,
                    IsComplex         = property.IsComplex,
                    IsEstate          = property.IsEstate,
                    Complex_Estate_No = property.Complex_Estate_No,
                    PropertyOwnerId   = property.PropertyOwnerId
                };
                foreach (var propertyOwner in propertyOwnersList)
                {
                    if (propertyOwner.UserId.ToString() == property.PropertyOwnerId)
                    {
                        var propertyOwnerItem = await _siteUserManager.FindByIdAsync(propertyOwner.UserId.ToString());

                        PropertywithOwner.PropertyOwnerFirstName    = propertyOwnerItem.FirstName;
                        PropertywithOwner.PropertyOwnerLastName     = propertyOwnerItem.LastName;
                        PropertywithOwner.PropertyOwnerEmailAddress = propertyOwnerItem.Email;
                        PropertywithOwner.PropertyOwnerContactNo    = propertyOwnerItem.PhoneNumber;
                    }
                }
                ;
                propertyList.Add(PropertywithOwner);
                //Assign Project Owner Name , Surname , Contact Number and Email.
            }
            //var model = _mapper.Map<List<Property>, List<PropertyViewModel>>(tb_property);
            return(View(propertyList));
        }
Esempio n. 6
0
        public async Task <VerifyEmailResult> ConfirmEmailAsync(string userId, string code)
        {
            IUserContext   userContext = null;
            IdentityResult result      = IdentityResult.Failed(null);

            var user = await userManager.FindByIdAsync(userId);

            if (user != null)
            {
                userContext = new UserContext(user);
                result      = await userManager.ConfirmEmailAsync(user, code);
            }

            return(new VerifyEmailResult(userContext, result));
        }
        public async Task HandleRegisterPostSuccess(
            ISiteContext site,
            RegisterViewModel viewModel,
            HttpContext httpContext,
            UserLoginResult loginResult,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            // just testing that on success the user can be updated with custom data
            if (loginResult.User != null)
            {
                var siteUser = await userManager.FindByIdAsync(loginResult.User.Id.ToString());

                if (siteUser != null)
                {
                    siteUser.FirstName = httpContext.Request.Form["FirstName"];
                    siteUser.LastName  = httpContext.Request.Form["LastName"];

                    var dobString = httpContext.Request.Form["DateOfBirth"];

                    DateTime dob;
                    var      dobParsed = DateTime.TryParse(dobString, out dob);
                    if (!dobParsed)
                    {
                        siteUser.DateOfBirth = dob.Date;
                    }

                    await userManager.UpdateAsync(siteUser);
                }
            }
            else
            {
                log.LogError("user was null in HandleRegisterPostSuccess, unable to update user with custom data");
            }
        }
Esempio n. 8
0
        public async Task <IActionResult> ConfirmEmail(string userId, string code)
        {
            if (signInManager.IsSignedIn(User))
            {
                return(this.RedirectToSiteRoot(Site));
            }
            if (userId == null || code == null)
            {
                return(View("Error"));
            }
            var user = await userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(View("Error"));
            }
            var result = await userManager.ConfirmEmailAsync(user, code);

            if (result.Succeeded)
            {
                if (Site.RequireApprovalBeforeLogin && !user.AccountApproved)
                {
                    await emailSender.AccountPendingApprovalAdminNotification(Site, user).ConfigureAwait(false);

                    return(RedirectToAction("PendingApproval", new { userId = user.Id, didSend = true }));
                }
            }

            return(View(result.Succeeded ? "ConfirmEmail" : "Error"));
        }
Esempio n. 9
0
        public async Task <IActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(View("Error"));
            }
            var user = await userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(View("Error"));
            }
            var result = await userManager.ConfirmEmailAsync(user, code);

            return(View(result.Succeeded ? "ConfirmEmail" : "Error"));
        }
Esempio n. 10
0
        public async Task <TimeZoneInfo> GetUserTimeZone()
        {
            HttpContext context = contextAccessor.HttpContext;

            if (context.User.Identity.IsAuthenticated)
            {
                SiteUser user = await userManager.FindByIdAsync(context.User.GetUserId());

                if ((user != null) && (user.TimeZoneId.Length > 0))
                {
                    return(TimeZoneInfo.FindSystemTimeZoneById(user.TimeZoneId));
                }
            }

            return(await GetSiteTimeZone());
        }
Esempio n. 11
0
        public async Task <string> GetUserTimeZoneId(CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var context = contextAccessor.HttpContext;

            if (context.User.Identity.IsAuthenticated)
            {
                var user = await userManager.FindByIdAsync(context.User.GetUserId());

                if ((user != null) && (!string.IsNullOrEmpty(user.TimeZoneId)))
                {
                    return(user.TimeZoneId);
                }
            }

            return(await GetSiteTimeZoneId(cancellationToken));
        }
Esempio n. 12
0
        public async Task<IActionResult> ConfirmEmail(string userId, string code)
        {

            if (userId == null || code == null)
            {
                return View("Error");
            }
            var user = await userManager.FindByIdAsync(userId);
            if (user == null)
            {
                return View("Error");
            }
            var result = await userManager.ConfirmEmailAsync(user, code);
            
            if (Site.RequireApprovalBeforeLogin && ! user.AccountApproved)
            {
                emailSender.AccountPendingApprovalAdminNotification(Site, user).Forget();

                return RedirectToAction("PendingApproval", new { userId = user.Id, didSend = true });
            }

            return View(result.Succeeded ? "ConfirmEmail" : "Error");
        }
Esempio n. 13
0
        public async Task <IActionResult> Index()
        {
            var user = await userManager.FindByIdAsync(HttpContext.User.GetUserId());

            var model = new AccountIndexViewModel
            {
                HasPassword       = (user.PasswordHash.Length > 0),
                PhoneNumber       = user.PhoneNumber,
                TwoFactor         = user.TwoFactorEnabled,
                Logins            = await userManager.GetLoginsAsync(user),
                BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user)
            };

            return(View(model));
        }
Esempio n. 14
0
 public async Task <SiteUser> GetUser(string userId)
 {
     return(await _userManager.FindByIdAsync(userId));
 }
Esempio n. 15
0
        public async Task <IActionResult> Index()
        {
            var user = await userManager.FindByIdAsync(HttpContext.User.GetUserId());

            var model = new AccountIndexViewModel
            {
                HasPassword       = (user.PasswordHash.Length > 0),
                PhoneNumber       = user.PhoneNumber.Length > 0 ? user.PhoneNumber : null,
                TwoFactor         = user.TwoFactorEnabled,
                Logins            = await userManager.GetLoginsAsync(user),
                BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user),
                TimeZone          = user.TimeZoneId
            };

            if (string.IsNullOrEmpty(model.TimeZone))
            {
                model.TimeZone = await timeZoneIdResolver.GetSiteTimeZoneId();
            }

            return(View(model));
        }
        // GET: /<controller>/
        public async Task <IActionResult> Index(int id)
        {
            var project = await _projectrepo.Get(id);

            var mappedproject = _mapper.Map <Project, ProjectViewModel>(project);
            var property      = await _propertyrepo.Get(project.PropertyId);

            var mappedproperty = _mapper.Map <Property, PropertyViewModel>(property);

            var propertyOwner = await _siteUserManager.FindByIdAsync(project.PropertyOwnerId.ToString());

            var draughtsman = await _siteUserManager.FindByIdAsync(project.DraughtsmanId.ToString());

            //string siteid = "1732d901-82c3-4c48-9e02-3049c8ea2738";
            var siteId = User.GetUserSiteIdAsGuid();
            ProjectDetailsViewModel projectDetails = new ProjectDetailsViewModel
            {
                ProjectId                  = project.ProjectId,
                ProjectName                = project.ProjectName,
                ProjectDescription         = project.ProjectDescription,
                MunicipalRefNo             = project.MunicipalRefNo,
                DateofSubmission           = project.DateofSubmission,
                MunicipalAssessmentOfficer = project.MunicipalAssessmentOfficer,
                AssessmentOfficerEmail     = project.AssessmentOfficerEmail,
                AssessmentOfficerContactNo = project.AssessmentOfficerContactNo,
                DateCreated                = project.DateCreated,
                DateModified               = project.DateModified,
                PropertyId                 = project.PropertyId,
                DraughtsmanId              = project.DraughtsmanId,
                ProjectStateId             = project.ProjectStateId,
                SiteId = property.SiteId,

                PropertyName      = property.PropertyName,
                PropertyAddress   = property.PropertyAddress,
                PropertyERF_LotNo = property.PropertyERF_LotNo,
                IsComplex         = property.IsComplex,
                IsEstate          = property.IsEstate,
                Complex_Estate_No = property.Complex_Estate_No,
                PropertySGNo      = property.PropertySGNo,

                PropertyOwnerFirstName = propertyOwner.FirstName,
                PropertyOwnerLastName  = propertyOwner.LastName,
                PropertyOwnerEmail     = propertyOwner.Email,
                // PropertyOwnerContactNo = propertyOwner.PhoneNumber,

                DraughtsmanFirstName = draughtsman.FirstName,
                DraughtsmanLastName  = draughtsman.LastName,
                DraughtsmanEmail     = draughtsman.Email,
                // DraughtsmanContactNo = draughtsman.PhoneNumber,
            };


            //mappedproject.Property = mappedproperty;*/

            var projectStatusItemViewModel = new ProjectStatusItemViewModel
            {
                ProjectId = id,
                Project   = projectDetails
                            // Project = mappedproject
            };

            var projectitemstatuses = await _repo.GetAllById(id);

            var projectItemStatusList = new List <ProjectItemStatusViewModel> {
            };

            foreach (var projectitemstatus in projectitemstatuses)
            {
                var mappeditemstatus = _mapper.Map <ProjectItemStatus, ProjectItemStatusViewModel>(projectitemstatus);
                projectItemStatusList.Add(mappeditemstatus);
            }
            projectStatusItemViewModel.ProjectItemStatuses = projectItemStatusList;
            return(View(projectStatusItemViewModel));
        }
Esempio n. 17
0
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            var sub  = context.Subject.GetSubjectId();
            var user = await _userManager.FindByIdAsync(sub);

            var principal = await _claimsFactory.CreateAsync(user);

            context.AddRequestedClaims(principal.Claims);

            var requestedClaims = context.RequestedClaimTypes.ToList();
            var foundClaims     = principal.Claims.Where(x => context.RequestedClaimTypes.Contains(x.Type)).Select(x => x.Type).ToList();
            var neededClaims    = requestedClaims.Except(foundClaims);
            var claimsToAdd     = new List <Claim>();

            //try to add needed claims if we know what they are
            foreach (var c in neededClaims)
            {
                if (c == JwtClaimTypes.Name)
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.Name, user.DisplayName));
                }

                if (c == JwtClaimTypes.Email)
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.Email, user.Email));
                }

                if (c == JwtClaimTypes.BirthDate && user.DateOfBirth.HasValue)
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.BirthDate, user.DateOfBirth.Value.ToString("YYYY-MM-DD")));
                }

                if (c == JwtClaimTypes.EmailVerified)
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.EmailVerified, user.EmailConfirmed.ToString().ToLowerInvariant()));
                }

                if (c == JwtClaimTypes.FamilyName && !string.IsNullOrWhiteSpace(user.LastName))
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.FamilyName, user.LastName));
                }

                if (c == JwtClaimTypes.GivenName && !string.IsNullOrWhiteSpace(user.FirstName))
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.GivenName, user.FirstName));
                }

                if (c == JwtClaimTypes.PhoneNumber && !string.IsNullOrWhiteSpace(user.PhoneNumber))
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.PhoneNumber, user.PhoneNumber));
                }

                if (c == JwtClaimTypes.PhoneNumberVerified)
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.PhoneNumberVerified, user.PhoneNumberConfirmed.ToString().ToLowerInvariant()));
                }

                if (c == JwtClaimTypes.WebSite && !string.IsNullOrWhiteSpace(user.WebSiteUrl))
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.WebSite, user.WebSiteUrl));
                }

                if (c == JwtClaimTypes.ZoneInfo && !string.IsNullOrWhiteSpace(user.TimeZoneId))
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.ZoneInfo, user.TimeZoneId));
                }

                if (c == JwtClaimTypes.Gender && !string.IsNullOrWhiteSpace(user.Gender))
                {
                    claimsToAdd.Add(new Claim(JwtClaimTypes.Gender, user.Gender));
                }
            }
            if (claimsToAdd.Count > 0)
            {
                context.IssuedClaims.AddRange(claimsToAdd);
            }
        }