/// <summary> /// Create user from Contract_JMMUser /// </summary> /// <returns></returns> private object CreateUser() { Request request = this.Request; Entities.JMMUser _user = (Entities.JMMUser) this.Context.CurrentUser; if (_user.IsAdmin == 1) { Contract_JMMUser user = this.Bind(); user.Password = Digest.Hash(user.Password); user.HideCategories = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); user.PlexUsers = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); if (new JMMServiceImplementation().SaveUser(user) == "") { return(APIStatus.statusOK()); } else { return(APIStatus.internalError()); } } else { return(APIStatus.adminNeeded()); } }
/// <summary> /// Create user from Contract_JMMUser /// </summary> /// <returns></returns> private object CreateUser() { Request request = this.Request; SVR_JMMUser _user = (SVR_JMMUser)this.Context.CurrentUser; if (_user.IsAdmin == 1) { JMMUser user = this.Bind(); user.Password = Digest.Hash(user.Password); user.HideCategories = ""; user.PlexUsers = ""; if (new ShokoServiceImplementation().SaveUser(user) == "") { return(APIStatus.statusOK()); } else { return(APIStatus.internalError()); } } else { return(APIStatus.adminNeeded()); } }
/// <summary> /// Set settings for LogRotator /// </summary> /// <returns></returns> private object SetRotateLogs() { Request request = this.Request; SVR_JMMUser user = (SVR_JMMUser)this.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.statusOK()); } else { return(APIStatus.adminNeeded()); } }
public PlexWebhookAuthenticated() : base("/plex") { this.RequiresAuthentication(); Get["/pin"] = o => CallPlexHelper(h => h.Authenticate()); 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.statusOK()); }); 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.statusOK()); }); 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.statusOK()); }); #if DEBUG Get["/test/{id}"] = o => Response.AsJson(CallPlexHelper(h => h.GetPlexSeries((int)o.id))); #endif }
/// <summary> /// Delete user from his ID /// </summary> /// <returns></returns> private object DeleteUser() { Request request = this.Request; JMMUser _user = (JMMUser)this.Context.CurrentUser; if (_user.IsAdmin == 1) { JMMUser user = this.Bind(); if (new JMMServiceImplementation().DeleteUser(user.JMMUserID) == "") { return(APIStatus.statusOK()); } else { return(APIStatus.internalError()); } } else { return(APIStatus.adminNeeded()); } }
/// <summary> /// change given user (by uid) password /// </summary> /// <returns></returns> private object ChangePassword(int uid) { Request request = this.Request; Entities.JMMUser _user = (Entities.JMMUser) this.Context.CurrentUser; if (_user.IsAdmin == 1) { JMMUser user = this.Bind(); if (new JMMServiceImplementation().ChangePassword(uid, user.Password) == "") { return(APIStatus.statusOK()); } else { return(APIStatus.internalError()); } } else { return(APIStatus.adminNeeded()); } }