protected UserContext LogOn(bool remember, IUserService userService, Func <IUserService, UserContext> logOnAction) { var context = logOnAction(userService); if (context != null) { ChalkableAuthentication.SignIn(context, false); if (context.DeveloperId.HasValue && !DemoUserService.IsDemoUser(context)) { DeveloperAuthentication.SignIn(context, remember); } } return(context); }
public ActionResult LogOnIntoDemo(string rolename, string prefix) { if (string.IsNullOrEmpty(prefix)) { Json(new ChalkableException(ChlkResources.ERR_DEMO_SCHOOL_INVALID_PREFIX)); } if (rolename.ToLower() == CoreRoles.DEVELOPER_ROLE.LoweredName) { var devContext = DeveloperAuthentication.GetUser(); if (devContext != null) { ChalkableAuthentication.SignIn(devContext, true); return(Redirect <HomeController>(c => c.Developer(null, null))); } throw new UnassignedUserException(); } var context = LogOn(false, userService => userService.DemoLogin(rolename, prefix)); if (context == null) { return(Json(new ChalkableException(string.Format(ChlkResources.USER_NOT_FOUND_IN_DEMO_SCHOOL, rolename, prefix)))); } if (rolename.ToLower() == CoreRoles.DISTRICT_ADMIN_ROLE.LoweredName) { return(Redirect <HomeController>(c => c.DistrictAdmin())); } if (rolename.ToLower() == CoreRoles.TEACHER_ROLE.LoweredName) { return(Redirect <HomeController>(c => c.Teacher())); } if (rolename.ToLower() == CoreRoles.STUDENT_ROLE.LoweredName) { return(Redirect <HomeController>(c => c.Student())); } throw new ChalkableSecurityException(ChlkResources.ERR_DEMO_SCHOOL_INCORRECT_ROLE); }
private void SwitchToRole(CoreRole role) { var context = MasterLocator.UserService.SwitchToRole(role); ChalkableAuthentication.SignIn(context, false); }