public string ChangePassword(int userID, string newPassword) { JMMUserRepository repUsers = new JMMUserRepository(); try { JMMUser jmmUser = repUsers.GetByID(userID); if (jmmUser == null) return "User not found"; jmmUser.Password = Digest.Hash(newPassword); repUsers.Save(jmmUser); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } return ""; }
public string SaveUser(Contract_JMMUser user) { JMMUserRepository repUsers = new JMMUserRepository(); try { bool existingUser = false; bool updateStats = false; JMMUser jmmUser = null; if (user.JMMUserID.HasValue) { jmmUser = repUsers.GetByID(user.JMMUserID.Value); if (jmmUser == null) return "User not found"; existingUser = true; } else { jmmUser = new JMMUser(); updateStats = true; } if (existingUser && jmmUser.IsAniDBUser != user.IsAniDBUser) updateStats = true; jmmUser.HideCategories = user.HideCategories; jmmUser.IsAniDBUser = user.IsAniDBUser; jmmUser.IsTraktUser = user.IsTraktUser; jmmUser.IsAdmin = user.IsAdmin; jmmUser.Username = user.Username; jmmUser.CanEditServerSettings = user.CanEditServerSettings; jmmUser.PlexUsers = user.PlexUsers; if (string.IsNullOrEmpty(user.Password)) jmmUser.Password = ""; // make sure that at least one user is an admin if (jmmUser.IsAdmin == 0) { bool adminExists = false; List<JMMUser> users = repUsers.GetAll(); foreach (JMMUser userOld in users) { if (userOld.IsAdmin == 1) { if (existingUser) { if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true; } else adminExists = true; } } if (!adminExists) return "At least one user must be an administrator"; } repUsers.Save(jmmUser); // update stats if (updateStats) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); foreach (AnimeSeries ser in repSeries.GetAll()) ser.QueueUpdateStats(); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } return ""; }
private static void CreateInitialUsers() { JMMUserRepository repUsers = new JMMUserRepository(); if (repUsers.GetAll().Count() > 0) return; JMMUser defaultUser = new JMMUser(); defaultUser.CanEditServerSettings = 1; defaultUser.HideCategories = ""; defaultUser.IsAdmin = 1; defaultUser.IsAniDBUser = 1; defaultUser.IsTraktUser = 1; defaultUser.Password = ""; defaultUser.Username = "******"; repUsers.Save(defaultUser); JMMUser familyUser = new JMMUser(); familyUser.CanEditServerSettings = 1; familyUser.HideCategories = "Ecchi,Nudity,Sex,Sexual Abuse,Horror,Erotic Game,Incest,18 Restricted"; familyUser.IsAdmin = 1; familyUser.IsAniDBUser = 1; familyUser.IsTraktUser = 1; familyUser.Password = ""; familyUser.Username = "******"; repUsers.Save(familyUser); }