Exemple #1
0
        public static void Exist()
        {
            var context = ApplicationIdentityContext.Create();

            IndexChecks.EnsureUniqueIndexOnUserName(context.ApplicationUsers);
            IndexChecks.EnsureUniqueIndexOnRoleName(context.IdentityRoles);
        }
        //DangVH. Create. End (02/11/2016)

        public static List <Category> ListAllCategory()
        {
            ApplicationIdentityContext Context    = ApplicationIdentityContext.Create();
            List <Category>            categories = Context.Categories.Find(_ => true).ToList();

            return(categories);
        }
        public static int GetGroupJustCreatedNumber()
        {
            ApplicationIdentityContext Context = ApplicationIdentityContext.Create();
            var groups = Context.Groups.Find(_ => true).ToList();
            var a      = groups.Where(x => x.CreatedDate.ToShortDateString().Equals(DateTime.Now.ToShortDateString()));

            return((int)a.Count());
        }
        public static List <Group> SuggestGroup(string id)
        {
            ApplicationIdentityContext Context = ApplicationIdentityContext.Create();
            List <Group> suggestGroups         = new List <Group>();
            var          groups = Context.Groups.Find(x => x.Tag.Equals(id)).ToList();

            suggestGroups = groups.Take(4).ToList();
            return(suggestGroups);
        }
Exemple #5
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            var context             = ApplicationIdentityContext.Create();
            var userManager         = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context.Users));
            var usuarioIdentityName = requestContext.HttpContext.User.Identity.Name;

            if (!string.IsNullOrWhiteSpace(usuarioIdentityName))
            {
                var usuario = userManager.FindByName(requestContext.HttpContext.User.Identity.Name);
                if (usuario != null)
                {
                    UserBase = usuario.UserInfo;
                }
            }
            base.Initialize(requestContext);
        }
Exemple #6
0
        public static List <Book> LastestBookInteracted(string userId)
        {
            List <Book> listBook = new List <Book>();
            ApplicationIdentityContext Context = ApplicationIdentityContext.Create();
            var user        = Context.Users.Find(x => x.Id.Equals(userId)).FirstOrDefault();
            var currentDate = DateTime.Now;

            foreach (var interactBook in user.Interacbook.DistinctBy(x => x.BookId).ToList())
            {
                if (interactBook.InteractTime.Date > currentDate.AddDays(-7).Date)
                {
                    listBook.Add(Context.Books.Find(x => x.Id.Equals(interactBook.BookId)).FirstOrDefault());
                }
            }
            listBook = listBook.Take(4).ToList();
            return(listBook);
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        public virtual void ConfigureAuth(IAppBuilder app)
        {
            PublicClientId = "self";

            var appcontext = ApplicationIdentityContext.Create();

            UserManagerFactory =
                () => new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(appcontext.Users));
            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath           = new PathString("/Token"),
                Provider                    = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
                AuthorizeEndpointPath       = new PathString("/api/UserProfile/ExternalLogin"),
                AccessTokenExpireTimeSpan   = TimeSpan.FromDays(30),
                AllowInsecureHttp           = true,
                ApplicationCanDisplayErrors = true
            };

            app.CreatePerOwinContext(ApplicationIdentityContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationRoleManager>(ApplicationRoleManager.Create);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                LoginPath = new PathString("/home/index"),
                Provider  = new CookieAuthenticationProvider
                {
                    OnValidateIdentity =
                        SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                            TimeSpan.FromMinutes(30),
                            (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            app.UseOAuthBearerTokens(OAuthOptions);


            app.UseRbacPermissions();
        }
Exemple #8
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            IdentityResult result;

            using (var context = ApplicationIdentityContext.Create())
            {
                var roleStore   = new RoleStore <IdentityRole>(context.Roles);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                await roleManager.CreateAsync(new IdentityRole()
                {
                    Name = "User"
                });

                var userStore   = new UserStore <ApplicationUser>(context.Users);
                var userManager = new UserManager <ApplicationUser>(userStore);

                var newUser = new ApplicationUser()
                {
                    UserName = model.Name, Email = model.Email
                };

                result = await UserManager.CreateAsync(newUser, model.Password);

                await userManager.AddToRoleAsync(newUser.Id, "Admin");
            }


            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
Exemple #9
0
 public AccountController()
 {
     _ctx = ApplicationIdentityContext.Create();
     _whiteLabelService = new WhiteLabelService();
 }
        //DangVH. Create. Start (02/11/2016)
        public static int GetBookNumber()
        {
            ApplicationIdentityContext Context = ApplicationIdentityContext.Create();

            return((int)Context.Books.Find(_ => true).Count());
        }
Exemple #11
0
 public WhiteLabelController()
 {
     _ctx = ApplicationIdentityContext.Create();
     _reservationService = new ReservationService();
     _whiteLabelService  = new WhiteLabelService();
 }
 public ReservationController()
 {
     _ctx = ApplicationIdentityContext.Create();
     _reservationService = new ReservationService();
 }
Exemple #13
0
        //DangVH. Create. Start (02/11/2016)
        private static ApplicationIdentityContext Context()
        {
            ApplicationIdentityContext context = ApplicationIdentityContext.Create();

            return(context);
        }
 public WhiteLabelService()
 {
     _ctx = ApplicationIdentityContext.Create();
 }