public static Musician Create(Core core, string title, string slug) { if (core == null) { throw new NullCoreException(); } Mysql db = core.Db; SessionState session = core.Session; if (core.Session.LoggedInMember == null) { return null; } if (!CheckMusicianNameUnique(core, slug)) { return null; } db.BeginTransaction(); InsertQuery iQuery = new InsertQuery(Musician.GetTable(typeof(Musician))); iQuery.AddField("musician_name", title); iQuery.AddField("musician_slug", slug); iQuery.AddField("musician_name_first", title.ToLower()[0]); iQuery.AddField("musician_reg_ip", session.IPAddress.ToString()); iQuery.AddField("musician_reg_date_ut", UnixTime.UnixTimeStamp()); long musicianId = db.Query(iQuery); Musician newMusician = new Musician(core, musicianId); MusicianMember member = MusicianMember.Create(core, newMusician, session.LoggedInMember); try { ApplicationEntry musicianAe = new ApplicationEntry(core, "Musician"); musicianAe.Install(core, newMusician); } catch { } try { ApplicationEntry galleryAe = new ApplicationEntry(core, "Gallery"); galleryAe.Install(core, newMusician); } catch { } try { ApplicationEntry guestbookAe = new ApplicationEntry(core, "GuestBook"); guestbookAe.Install(core, newMusician); } catch { } Access.CreateGrantForPrimitive(core, newMusician, User.GetEveryoneGroupKey(core), "VIEW"); Access.CreateGrantForPrimitive(core, newMusician, User.GetRegisteredUsersGroupKey(core), "COMMENT"); Access.CreateGrantForPrimitive(core, newMusician, User.GetRegisteredUsersGroupKey(core), "COMMENT_GIGS"); return newMusician; }
public void ApplicationInstall(object sender, EventArgs e) { AuthoriseRequestSid(); int id; try { id = int.Parse(core.Http.Query["id"]); } catch { core.Display.ShowMessage("Error", "Error!"); return; } /*try {*/ ApplicationEntry ae = new ApplicationEntry(core, id); bool success = ae.Install(core, core.Session.LoggedInMember, Owner); /*} catch { }*/ if (success) { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Application Installed", "The application has been installed to your profile."); } else { SetRedirectUri(BuildUri()); core.Display.ShowMessage("Application Not Installed", "The application has not been installed to your profile."); } }
public static UserGroup Create(Core core, string groupTitle, string groupSlug, string groupDescription, long groupCategory, string groupType) { if (core == null) { throw new NullCoreException(); } Mysql db = core.Db; SessionState session = core.Session; if (core.Session.LoggedInMember == null) { return null; } if (!CheckGroupNameUnique(core, groupSlug)) { return null; } switch (groupType) { case "open": groupType = "OPEN"; break; case "request": groupType = "REQUEST"; break; case "closed": groupType = "CLOSED"; break; case "private": groupType = "PRIVATE"; break; default: return null; } db.BeginTransaction(); InsertQuery iQuery = new InsertQuery(UserGroup.GetTable(typeof(UserGroup))); iQuery.AddField("group_name", groupSlug); iQuery.AddField("group_domain", string.Empty); long groupId = db.Query(iQuery); iQuery = new InsertQuery(UserGroupInfo.GetTable(typeof(UserGroupInfo))); iQuery.AddField("group_id", groupId); iQuery.AddField("group_name", groupSlug); iQuery.AddField("group_name_display", groupTitle); iQuery.AddField("group_type", groupType); iQuery.AddField("group_abstract", groupDescription); iQuery.AddField("group_reg_date_ut", UnixTime.UnixTimeStamp()); iQuery.AddField("group_operators", 1); iQuery.AddField("group_officers", 0); iQuery.AddField("group_members", 1); iQuery.AddField("group_category", groupCategory); iQuery.AddField("group_gallery_items", 0); iQuery.AddField("group_home_page", "/profile"); iQuery.AddField("group_style", string.Empty); iQuery.AddField("group_reg_ip", session.IPAddress.ToString()); iQuery.AddField("group_icon", 0); iQuery.AddField("group_bytes", 0); iQuery.AddField("group_views", 0); db.Query(iQuery); if (groupType != "PRIVATE") { db.UpdateQuery(string.Format("UPDATE global_categories SET category_groups = category_groups + 1 WHERE category_id = {0}", groupCategory)); } db.UpdateQuery(string.Format("INSERT INTO group_members (user_id, group_id, group_member_approved, group_member_ip, group_member_date_ut) VALUES ({0}, {1}, 1, '{2}', UNIX_TIMESTAMP())", session.LoggedInMember.UserId, groupId, Mysql.Escape(session.IPAddress.ToString()))); db.UpdateQuery(string.Format("INSERT INTO group_operators (user_id, group_id) VALUES ({0}, {1})", session.LoggedInMember.UserId, groupId)); UserGroup newGroup = new UserGroup(core, groupId); // Install a couple of applications try { ApplicationEntry profileAe = new ApplicationEntry(core, "Profile"); profileAe.Install(core, newGroup); } catch { } try { ApplicationEntry groupsAe = new ApplicationEntry(core, "Groups"); groupsAe.Install(core, newGroup); } catch { } try { ApplicationEntry galleryAe = new ApplicationEntry(core, "Gallery"); galleryAe.Install(core, newGroup); } catch { } try { ApplicationEntry guestbookAe = new ApplicationEntry(core, "GuestBook"); guestbookAe.Install(core, newGroup); } catch { } return newGroup; }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="userName"></param> /// <param name="eMail"></param> /// <param name="password"></param> /// <param name="passwordConfirm"></param> /// <returns>Null if registration failed</returns> public static User Register(Core core, string userName, string eMail, string password, string passwordConfirm) { if (core == null) { throw new NullCoreException(); } Mysql db = core.Db; SessionState session = core.Session; string passwordClearText = password; if (!CheckUserNameUnique(db, userName)) { return null; } if (!CheckUserNameValid(userName)) { return null; } password = VerifyPasswordMatch(password, passwordConfirm); if (password == "") { return null; } string activateKey = User.GenerateActivationSecurityToken(); InsertQuery query = new InsertQuery("user_keys"); query.AddField("user_name", userName); query.AddField("user_name_lower", userName.ToLower()); query.AddField("user_domain", ""); query.AddField("user_name_first", userName[0].ToString().ToLower()); db.BeginTransaction(); long userId = db.Query(query); if (userId < 0) { db.RollBackTransaction(); throw new InvalidUserException(); } query = new InsertQuery("user_info"); query.AddField("user_id", userId); query.AddField("user_name", userName); query.AddField("user_alternate_email", eMail); query.AddField("user_password", password); query.AddField("user_reg_date_ut", UnixTime.UnixTimeStamp()); query.AddField("user_activate_code", activateKey); query.AddField("user_reg_ip", session.IPAddress.ToString()); query.AddField("user_home_page", "/profile"); query.AddField("user_bytes", 0); query.AddField("user_status_messages", 0); query.AddField("user_show_bbcode", 0x07); query.AddField("user_show_custom_styles", true); query.AddField("user_email_notifications", true); query.AddField("user_new_password", ""); query.AddField("user_last_visit_ut", -30610224000L); query.AddField("user_language", "en"); if (db.Query(query) < 0) { throw new InvalidUserException(); } query = new InsertQuery("user_profile"); query.AddField("user_id", userId); query.AddField("profile_date_of_birth_ut", -30610224000L); // TODO: ACLs db.Query(query); User newUser = new User(core, userId); UserEmail registrationEmail = UserEmail.Create(core, newUser, eMail, EmailAddressTypes.Personal, true); // Install a couple of applications try { ApplicationEntry profileAe = new ApplicationEntry(core, "Profile"); profileAe.Install(core, newUser); } catch { } try { ApplicationEntry mailAe = new ApplicationEntry(core, "Mail"); mailAe.Install(core, newUser); } catch { } try { ApplicationEntry galleryAe = new ApplicationEntry(core, "Gallery"); galleryAe.Install(core, newUser); } catch { } try { ApplicationEntry guestbookAe = new ApplicationEntry(core, "GuestBook"); guestbookAe.Install(core, newUser); } catch { } try { ApplicationEntry groupsAe = new ApplicationEntry(core, "Groups"); groupsAe.Install(core, newUser); } catch { } try { ApplicationEntry networksAe = new ApplicationEntry(core, "Networks"); networksAe.Install(core, newUser); } catch { } try { ApplicationEntry calendarAe = new ApplicationEntry(core, "Calendar"); calendarAe.Install(core, newUser); } catch { } string activateUri = string.Format("{0}register/?mode=activate&id={1}&key={2}", core.Hyperlink.Uri, userId, activateKey); Template emailTemplate = new Template(core.Http.TemplateEmailPath, "registration_welcome.html"); emailTemplate.Parse("SITE_TITLE", core.Settings.SiteTitle); emailTemplate.Parse("U_SITE", core.Hyperlink.StripSid(core.Hyperlink.AppendAbsoluteSid(core.Hyperlink.BuildHomeUri()))); emailTemplate.Parse("TO_NAME", userName); emailTemplate.Parse("U_ACTIVATE", activateUri); emailTemplate.Parse("USERNAME", userName); emailTemplate.Parse("PASSWORD", passwordClearText); core.Email.SendEmail(eMail, "Activate your account. Welcome to " + core.Settings.SiteTitle, emailTemplate); Access.CreateAllGrantsForOwner(core, newUser); Access.CreateGrantForPrimitive(core, newUser, User.GetEveryoneGroupKey(core), "VIEW"); Access.CreateGrantForPrimitive(core, newUser, User.GetEveryoneGroupKey(core), "VIEW_STATUS"); Access.CreateGrantForPrimitive(core, newUser, Friend.GetFriendsGroupKey(core), "COMMENT"); Access.CreateGrantForPrimitive(core, newUser, Friend.GetFriendsGroupKey(core), "VIEW_FRIENDS"); Access.CreateGrantForPrimitive(core, newUser, Friend.GetFamilyGroupKey(core), "VIEW_FAMILY"); core.Search.Index(newUser); return newUser; }