protected Task <UserViewFull> SpecialWrite(UserViewFull original, UserViewFull updated, Requester requester) { //All of these force a public update, which is honestly simpler if (original.avatar != updated.avatar || original.username != updated.username || original.special != updated.special) { return(service.WriteAsync(updated, requester)); } else { return(service.WriteSpecialAsync(original.id, requester, p => { //Regardless of if these were updated or not, set them anyway. Shouldn't do any harm... service.Source.SetEmail(p, updated); service.Source.SetHidelist(p, updated); service.Source.SetPassword(p, updated); })); } }
public ModuleViewServiceTests() { userService = CreateService <UserViewService>(); superUser = userService.WriteAsync(new UserViewFull() { username = "******" }, system).Result; basicUser = userService.WriteAsync(new UserViewFull() { username = "******" }, system).Result; super = new Requester() { userId = superUser.id }; basic = new Requester() { userId = basicUser.id }; sysConfig.SuperUsers.Add(superUser.id); }
public void SubcommandArguments_User() { //The subcommands variable exists but is the wrong type, the module system shouldn't care var modview = new ModuleView() { name = "test", code = @" subcommands = {[""wow""]={[""arguments""]={""first_user"",""second_user""}} } function command_wow(uid, user1, user2) return ""Id: "" .. uid .. "" User1: "" .. user1 .. "" User2: "" .. user2 end" }; //Fragile test, should inject a fake user service that always says the user is good. oh well userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); userService.WriteAsync(new UserViewFull() { username = "******" }, new Requester() { system = true }).Wait(); var mod = service.UpdateModule(modview); var result = service.RunCommand("test", "wow 1 2(lol_username!)", new Requester() { userId = 8 }); Assert.Equal("Id: 8 User1: 1 User2: 2", result); }
public async Task <ReadTestUnit> CreateUnitAsync() { //First, create some users! var unit = new ReadTestUnit(); var requester = new Requester() { system = true }; unit.commonUser = await userService.WriteAsync(new UserViewFull() { username = "******" }, requester); unit.specialUser = await userService.WriteAsync(new UserViewFull() { username = "******" }, requester); unit.commonContent = await contentService.WriteAsync(new ContentView() { name = "commonContent", parentId = 0, permissions = new Dictionary <long, string>() { { 0, "cr" } } }, requester); unit.specialContent = await contentService.WriteAsync(new ContentView() { name = "specialContent", parentId = 0, permissions = new Dictionary <long, string>() { { unit.specialUser.id, "cr" } } }, requester); return(unit); }
public async Task <ActionResult <UserView> > Register([FromBody] UserCredential user) { //One day, fix these so they're the "standard" bad object request from model validation!! //Perhaps do custom validation! if (user.username == null) { return(BadRequest("Must provide a username!")); } if (user.email == null) { return(BadRequest("Must provide an email!")); } if (string.IsNullOrWhiteSpace(user.password)) { return(BadRequest("Must provide a password!")); } if (!ValidUsername(user.username)) { return(BadRequest("Bad username: no spaces!")); } var requester = GetRequesterNoFail(); if (await service.FindByUsernameAsync(user.username, requester) != null || await service.FindByEmailAsync(user.email, requester) != null) { return(BadRequest("This user already seems to exist!")); } var fullUser = mapper.Map <UserViewFull>(user); SetPassword(fullUser, fullUser.password); fullUser.registrationKey = Guid.NewGuid().ToString(); return(await ThrowToAction(async() => mapper.Map <UserView>(await service.WriteAsync(fullUser, requester)))); }