예제 #1
0
        /// <summary>
        /// Get the first user id with the given role.
        /// </summary>
        public static string GetUserRoleId(CmagruDBContext dBContext, string roleName)
        {
            var role     = dBContext.Roles.First(x => x.NormalizedName == roleName.ToUpper());
            var userRole = dBContext.UserRoles.FirstOrDefault(x => x.RoleId == role.Id);

            return(userRole.UserId);
        }
예제 #2
0
        public static string GetUserRole(CmagruDBContext dBContext, ApplicationUser user)
        {
            var role = dBContext.UserRoles.FirstOrDefault(x => x.UserId == user.Id);

            if (role == null)
            {
                return(null);
            }
            return(dBContext.Roles.First(x => x.Id == role.RoleId).Name);
        }
예제 #3
0
 public ImgControl(
     ILogger logger,
     CmagruDBContext context,
     UserManager <ApplicationUser> userManager,
     IEmailService emailService)
 {
     _logger       = logger;
     _context      = context;
     _userManager  = userManager;
     _emailService = emailService;
 }
 public PhotoRoomController(
     ILogger <AccountController> logger,
     CmagruDBContext context,
     UserManager <ApplicationUser> userManager,
     IEmailService emailService)
 {
     _logger      = logger;
     _context     = context;
     _userManager = userManager;
     _imgCtrl     = new ImgControl(_logger, _context, _userManager, emailService);
 }
 public PhotoWallController(
     ILogger <AccountController> logger,
     CmagruDBContext context,
     UserManager <ApplicationUser> userManager,
     IEmailService emailService,
     IAuthorizationService authorizationService)
 {
     _logger               = logger;
     _context              = context;
     _userManager          = userManager;
     _authorizationService = authorizationService;
     _imgCtrl              = new ImgControl(logger, context, userManager, emailService);
 }
예제 #6
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     CmagruDBContext context,
     ILogger <AccountController> logger,
     IMapper mapper,
     IEmailService emailService)
 {
     System.Security.Claims.ClaimsPrincipal a = User;
     _logger        = logger;
     _mapper        = mapper;
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailService  = emailService;
     _context       = context;
 }
예제 #7
0
        /// <summary>
        /// Send email notification to target, if email is
        /// confirmed and target allows notifications.
        /// </summary>
        public static void SendEmailNotif(
            CmagruDBContext context,
            IEmailService emailService,
            string targetUserId,
            string subject,
            string content)
        {
            var targetUser = context.Users.Find(targetUserId);

            if (targetUser == null)
            {
                return;
            }
            if (!targetUser.EmailConfirmed)
            {
                return;
            }

            var settings = context.GetUserSettings
                           .FirstOrDefault(x => x.UserId == targetUser.Id);

            if (settings == null)
            {
                return;
            }
            if (!settings.SendEmailNotifs)
            {
                return;
            }

            emailService.Send(new EmailMessage
            {
                ToAddress = targetUser.Email,
                Subject   = subject,
                Content   = content
            });
        }