/// <summary> /// Delete user from his ID /// </summary> /// <returns></returns> private object DeleteUser() { SVR_JMMUser _user = (SVR_JMMUser)Context.CurrentUser; if (_user.IsAdmin == 1) { SVR_JMMUser user = this.Bind(); return(new ShokoServiceImplementation().DeleteUser(user.JMMUserID) == string.Empty ? APIStatus.OK() : APIStatus.InternalError()); } return(APIStatus.AdminNeeded()); }
/// <summary> /// Create user from Contract_JMMUser /// </summary> /// <returns></returns> private object CreateUser() { SVR_JMMUser _user = (SVR_JMMUser)Context.CurrentUser; if (_user.IsAdmin == 1) { JMMUser user = this.Bind(); user.Password = Digest.Hash(user.Password); user.HideCategories = string.Empty; user.PlexUsers = string.Empty; return(new ShokoServiceImplementation().SaveUser(user) == string.Empty ? APIStatus.OK() : APIStatus.InternalError()); } return(APIStatus.AdminNeeded()); }
public PlexWebhookAuthenticated() : base("/plex") { this.RequiresAuthentication(); //Get["/pin"] = o => CallPlexHelper(h => h.Authenticate()); Get["/loginurl"] = o => CallPlexHelper(h => h.LoginUrl); Get["/pin/authenticated"] = o => $"{CallPlexHelper(h => h.IsAuthenticated)}"; Get["/token/invalidate"] = o => CallPlexHelper(h => { h.InvalidateToken(); return(true); }); Get["/sync", true] = async(x, ct) => await Task.Factory.StartNew(() => { new CommandRequest_PlexSyncWatched((JMMUser)this.Context.CurrentUser).Save(); return(APIStatus.OK()); }); Get["/sync/all", true] = async(x, ct) => await Task.Factory.StartNew(() => { if (((JMMUser)this.Context.CurrentUser).IsAdmin != 1) { return(APIStatus.AdminNeeded()); } ShokoServer.Instance.SyncPlex(); return(APIStatus.OK()); }); Get["/sync/{id}", true] = async(x, ct) => await Task.Factory.StartNew(() => { if (((JMMUser)this.Context.CurrentUser).IsAdmin != 1) { return(APIStatus.AdminNeeded()); } JMMUser user = RepoFactory.JMMUser.GetByID(x.id); ShokoServer.Instance.SyncPlex(); return(APIStatus.OK()); }); #if DEBUG Get["/test/dir"] = o => Response.AsJson(CallPlexHelper(h => h.GetDirectories())); Get["/test/lib/{id}"] = o => Response.AsJson(CallPlexHelper(h => ((SVR_Directory)h.GetDirectories().FirstOrDefault(d => d.Key == (int)o.id))?.GetShows())); #endif }
/// <summary> /// Set settings for LogRotator /// </summary> /// <returns></returns> private object SetRotateLogs() { Request request = Request; SVR_JMMUser user = (SVR_JMMUser)Context.CurrentUser; Logs rotator = this.Bind(); if (user.IsAdmin == 1) { ServerSettings.RotateLogs = rotator.rotate; ServerSettings.RotateLogs_Zip = rotator.zip; ServerSettings.RotateLogs_Delete = rotator.delete; ServerSettings.RotateLogs_Delete_Days = rotator.days.ToString(); return(APIStatus.OK()); } return(APIStatus.AdminNeeded()); }
/// <summary> /// change given user (by uid) password /// </summary> /// <returns></returns> private object ChangePassword(int uid) { SVR_JMMUser thisuser = (SVR_JMMUser)Context.CurrentUser; SVR_JMMUser user = this.Bind(); if (thisuser.IsAdmin == 1) { return(new ShokoServiceImplementation().ChangePassword(uid, user.Password) == string.Empty ? APIStatus.OK() : APIStatus.InternalError()); } if (thisuser.JMMUserID == user.JMMUserID) { return(new ShokoServiceImplementation().ChangePassword(uid, user.Password) == string.Empty ? APIStatus.OK() : APIStatus.InternalError()); } return(APIStatus.AdminNeeded()); }