public ActionResult Index() { if (User == null || User.Identity == null || !User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } else { var userid = User.Identity.GetUserId(); //get current user id WebSiteDBContext context = new WebSiteDBContext(); Client client = context.Set <Client>() .Include("Applications") .Where(c => c.Id == userid) .FirstOrDefault(); if (client != null) { return(RedirectToAction("Index", "Client")); } else { return(RedirectToAction("Index", "Administrator")); } } }
// GET: /Client/Applications public ActionResult Applications(WebSiteDBContext context) { string idClient = User.Identity.GetUserId(); //get current user id var applications = _clientRepository. getClientApplications(context, idClient); return(View("../Application/Applications", applications)); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { WebSiteDBContext db = (WebSiteDBContext)validationContext.GetService(typeof(WebSiteDBContext)); var currentUser = (UserViewModel)validationContext.ObjectInstance; var UserInDb = db.Users.Where(x => x.UserName == currentUser.UserName).FirstOrDefault(); if (UserInDb != null) { return(new ValidationResult("Sorry,User name is in use")); } return(ValidationResult.Success); }
// GET: /Client/Applications public ActionResult OperationsDocuments(WebSiteDBContext context, int operationId) { string idClient = User.Identity.GetUserId(); //get current user id if (_operationRepository.AutorizeToClient(context, operationId, idClient)) { var operations = _operationRepository. OperationDocumentsDisplay(context, operationId); return(View("../Document/Documents", operations)); } else { return(RedirectToAction("Index", "Default")); } }
public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(WebSiteDBContext.Create); app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create); app.CreatePerOwinContext <RoleManager <ApplicationRole> >((options, context) => new RoleManager <ApplicationRole>( new RoleStore <ApplicationRole>(context.Get <WebSiteDBContext>()))); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); var _context = new WebSiteDBContext(); var roleStore = new RoleStore <IdentityRole>(_context); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <ApplicationUser>(_context); var userManager = new UserManager <ApplicationUser>(userStore); //Ajouter le role Administrateur s'il n'existe pas var role = roleManager.FindByName(RoleNames.ROLE_ADMINISTRATOR); if (role == null) { roleManager.Create(new IdentityRole(RoleNames.ROLE_ADMINISTRATOR)); } //Ajouter le role Client s'il n'existe pas role = roleManager.FindByName(RoleNames.ROLE_CLIENT); if (role == null) { roleManager.Create(new IdentityRole(RoleNames.ROLE_CLIENT)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); var context = new WebSiteDBContext(); var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); userManager.AddToRole(user.Id, RoleNames.ROLE_ADMINISTRATOR); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Default")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ProductRepository(WebSiteDBContext ctx) { _ctx = ctx; }
public ApplicationRoleStore(WebSiteDBContext context) : base(context) { }
public UserRepository(WebSiteDBContext ctx) { _ctx = ctx; }