public ActionResult Verify(string userName, string password)
 {
     using (SemplestEntities dbContext = new SemplestEntities())
     {
         var creds = dbContext.Credentials.Where(c => c.Username == userName && c.Password == password);
         if (creds.Count() == 1)
         {
             Session[Semplest.SharedResources.SEMplestConstants.SESSION_USERID] = creds.First().UsersFK;
             if (creds.First().User.UserRolesAssociations.First().RolesFK == 2)
                 //means this is an admin user
                 return RedirectToAction("Index", "Home");
             else
                 if (creds.First().User.IsRegistered)
                     return RedirectToAction("Index", "Home");
                 else
                 {
                     Semplest.SharedResources.Models.ProfileModel pm = new Models.ProfileModel();
                     pm.UserName = userName;
                     pm.Password1 = password;
                     return PartialView("_Password", pm);
                 }
         }
         Semplest.SharedResources.Models.ProfileModel pm2 = new Models.ProfileModel();
         pm2.UserName = userName + userName;
         pm2.Password1 = password;
         return View(pm2);
     }
 }
        private string PopulateMissingChildProfileBody(Models.ProfileModel profile)
        {
            var body = string.Empty;

            using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Template.htm")))
            {
                body = reader.ReadToEnd();
            }
            body = body.Replace("{FirstName}", profile.FirstName);
            body = body.Replace("{LastName}", profile.LastName);
            body = body.Replace("{Sex}", profile.Sex);
            body = body.Replace("{Description}", profile.Description);
            return(body);
        }
Exemple #3
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                var currentUser = await S.UserManager.GetUserAsync(HttpContext.User);

                if (currentUser == null)
                {
                    throw new UnauthorizedAccessException("Can't determine target user");
                }
                else
                {
                    id = currentUser.Id;
                }
            }

            var targetUser = await S.Db.Users.AsNoTracking()
                             .Include(u => u.Actions)
                             .ThenInclude(p => p.ProfileObject)
                             .Include(u => u.Actions)
                             .ThenInclude(p => p.PostObject)
                             .Include(u => u.Actions)
                             .ThenInclude(p => p.CommentaryObject)
                             .Include(u => u.Actions)
                             .ThenInclude(p => p.Owner)

                             .Include(u => u.Violations)
                             .ThenInclude(v => v.Reporter)
                             .Include(u => u.Violations)
                             .ThenInclude(p => p.ProfileObject)
                             .Include(u => u.Violations)
                             .ThenInclude(p => p.PostObject)
                             .Include(u => u.Violations)
                             .ThenInclude(p => p.CommentaryObject)

                             .Include(u => u.Reports)
                             .ThenInclude(v => v.Reporter)
                             .Include(u => u.Reports)
                             .ThenInclude(p => p.ProfileObject)
                             .Include(u => u.Reports)
                             .ThenInclude(p => p.PostObject)
                             .Include(u => u.Reports)
                             .ThenInclude(p => p.CommentaryObject)

                             //.Include(u => u.ReportedReports)
                             //.ThenInclude(v => v.Reporter)
                             .Include(u => u.ReportedReports)
                             .ThenInclude(p => p.ProfileObject)
                             .Include(u => u.ReportedReports)
                             .ThenInclude(p => p.PostObject)
                             .Include(u => u.ReportedReports)
                             .ThenInclude(p => p.CommentaryObject)

                             .Include(u => u.Profile)
                             .ThenInclude(p => p.ViewStatistic)
                             .Include(u => u.Status)
                             .FirstOrDefaultAsync(u => u.Id == id);

            Profile = new Models.ProfileModel()
            {
                Permissions      = await S.Permissions.GetProfilePermissionsAsync(id),
                ContactHelpEmail = await S.ContactEmailProvider.GetHelpContactEmailAsync(),
                IsCurrentUser    = targetUser.UserName == S.HttpContext.User.Identity.Name,
                TargetUser       = new UserProfileModel()
                {
                    About            = targetUser.Profile.About,
                    IsEmailConfirmed = targetUser.EmailConfirmed,
                    Role             = targetUser.Role.GetEnumValueDescription(),
                    UserId           = targetUser.Id,
                    User             = targetUser.UserName,
                    ViewStatistic    = targetUser.Profile.ViewStatistic,
                    EMail            = targetUser.Email,
                    RegistrationDate = targetUser.Profile.RegistrationDate,
                    State            = targetUser.Status.State
                },
                Actions = targetUser.Actions.Select(a => new UserActionModel()
                {
                    ActionDate   = a.ActionDate,
                    ActionObject = a.ActionObject,
                    Type         = a.ActionType,
                    IsSelfAction = a.ProfileObject?.Id == targetUser.Profile.Id || a.Owner?.Id == targetUser.Id,
                }).ToArray(),
                Posts = await S.Db.Posts.Where(p => p.Author.Id == targetUser.Id)
                        .Select(p => new PostProfileModel()
                {
                    BodyPreview     = p.BodyPreview,
                    CreationTime    = p.CreationTime,
                    IsDeleted       = p.IsDeleted,
                    ModerationState = p.ModerationInfo.State,
                    PostId          = p.Id,
                    Title           = p.Title,
                }).ToListAsync(),
                ProfileImage = new ProfileImageModel()
                {
                    RelativeUri = targetUser.Profile.Image
                },
                ReportedReports = targetUser.ReportedReports.Select(r => new ReportModel()
                {
                    Reporter     = r.Reporter.UserName,
                    ReporterId   = r.Reporter.Id,
                    CreationTime = r.CreationDate,
                    Object       = r.Object
                }).ToArray(),
                Reports = targetUser.Reports.Select(r => new ReportModel()
                {
                    Reporter     = r.Reporter.UserName,
                    ReporterId   = r.Reporter.Id,
                    CreationTime = r.CreationDate,
                    Object       = r.Object
                }).ToArray(),
                Violations = targetUser.Violations.Select(v => new ViolationModel()
                {
                    CreationTime = v.CreationDate,
                    Object       = v.Object,
                    Description  = v.Description,
                    Reporter     = v.Reporter.UserName,
                    ReporterId   = v.Reporter.Id
                }).ToArray()
            };

            await S.DbUpdator.UpdateViewStatisticAsync(S.HttpContext.User?.Identity?.IsAuthenticated ?? false, Profile.TargetUser.ViewStatistic);

            await S.Db.SaveChangesAsync();

            return(Page());
        }