コード例 #1
0
 public AccountController()
 {
     _userManager =
         new ApplicationUserManager(
             new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString()));
     _galleonUserStore = new GalleonUserStore(MongoUtil <GalleonRegistrationModel> .GetDefaultConnectionString());
 }
コード例 #2
0
 public MailController()
 {
     _mail        = new MailStore <Mail>(MongoUtil <Mail> .GetDefaultConnectionString());
     _userManager =
         new ApplicationUserManager(
             new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString()));
     _check = new CheckStore <CheckModel>(MongoUtil <Mail> .GetDefaultConnectionString());
 }
コード例 #3
0
        public async Task <IHttpActionResult> ProfileData()
        {
            var currentUser = User.Identity.Name;

            using (
                var repo =
                    new ApplicationUserManager(
                        new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString())))
            {
                var user = await repo.FindByNameAsync(currentUser);

                var profiledata = new Profile
                {
                    Email    = user.Email,
                    Name     = user.Name,
                    Company  = user.Company,
                    Image    = user.Image,
                    UserName = user.UserName
                };

                return(Ok(profiledata));
            }
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            /*context.OwinContext.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Origin, X-Requested-With, Content-Type, Accept" });
             * context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
             * context.OwinContext.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "GET,POST,OPTIONS,PUT" });*/

            using (var repo = new ApplicationUserManager(new UserStore <Identity.Core.IdentityUser>(MongoUtil <Identity.Core.IdentityUser> .GetDefaultConnectionString())))
            {
                var user = await repo.FindAsync(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                foreach (var role in user.Roles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, role));
                }
                identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
                var props = CreateProperties(user);

                var ticket = new AuthenticationTicket(identity, props);

                context.Validated(ticket);
            }
        }
コード例 #5
0
        //protected internal MongoCollection<IEvent> collection;

        public MongoEventStore() : this(MongoUtil <Guid> .GetDefaultConnectionString())
        {
        }
コード例 #6
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            using (var repo = new ApplicationUserManager(new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString())))
            {
                var user = await repo.FindAsync(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                foreach (var role in user.Roles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, role));
                }
                identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));

                context.Validated(identity);
            }
        }
コード例 #7
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var userName = actionContext.RequestContext.Principal.Identity.Name;

            if (string.IsNullOrEmpty(userName))
            {
                HandleUnauthorizedRequest(actionContext);
            }
            else
            {
                using (var repo = new ApplicationUserManager(new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString())))
                {
                    var user = repo.FindByNameAsync(userName).Result;

                    if (user == null)
                    {
                        HandleUnauthorizedRequest(actionContext);
                    }
                    else
                    {
                        if (AccessLevel == null)
                        {
                            base.OnAuthorization(actionContext);
                        }
                        else
                        {
                            if (user.Roles.Contains(AccessLevel))
                            {
                                base.OnAuthorization(actionContext);
                            }
                            else
                            {
                                HandleUnauthorizedRequest(actionContext);
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
 public MongoRepository(string connectionString)
 {
     _collection = MongoUtil.GetCollectionFromConnectionString <T>(MongoUtil.GetDefaultConnectionString());
 }
コード例 #9
0
 public MongoRepository()
     : this(MongoUtil.GetDefaultConnectionString())
 {
 }
コード例 #10
0
 public ImageController()
 {
     _userManager =
         new ApplicationUserManager(
             new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString()));
 }
コード例 #11
0
 public AccountController(IUnitOfWork unitOfWork)
 {
     _userManager = new ApplicationUserManager(new UserStore <Account>(MongoUtil <Account> .GetDefaultConnectionString()));
     _unitOfWork  = unitOfWork;
 }
コード例 #12
0
        public async Task Add_ForUserManager_ShouldAddUserWithRoles_Test()
        {
            var userManager = new ApplicationUserManager(new UserStore <IdentityUser>(MongoUtil <IdentityUser> .GetDefaultConnectionString()));
            var password    = "******";
            var userName    = "******";
            var testRole    = "testRole 123";

            var identityUser = new IdentityUser
            {
                UserName = userName,
                Email    = "*****@*****.**"
            };

            identityUser.Roles.Add(testRole);

            await userManager.CreateAsync(identityUser, password);

            var user = await userManager.FindByNameAsync(userName);

            Assert.That(user != null);
            Assert.That(user.Roles.Count == 1);
        }
コード例 #13
0
        public async Task Add_ForRoleManager_ShouldAddRole_Test()
        {
            var roleManager = new ApplicationRoleManager(new RoleStore <IdentityRole>(MongoUtil <IdentityUser> .GetDefaultConnectionString()));
            var role        = "TestRole";


            await roleManager.CreateAsync(new IdentityRole(role));

            Assert.That(await roleManager.FindByNameAsync(role) != null);
        }