app/models/camaleon_cms/site.rb in camaleon_cms-2.1.2.1 vs app/models/camaleon_cms/site.rb in camaleon_cms-2.2.0

- old
+ new

@@ -250,10 +250,21 @@ # check if current site is in maintenance or not def is_maintenance? self.status == 'maintenance' end + # return the anonymous user + # if the anonymous user not exist, will create one + def get_anonymous_user + user = self.users.where(username: 'anonymous').first + unless user.present? + pass = "anonymous#{rand(9999)}" + user = self.users.create({email: 'anonymous_user@local.com', username: 'anonymous', password: pass, password_confirmation: pass, first_name: 'Anonymous'}) + end + user + end + private # destroy all things before site destroy def destroy_site unless PluginRoutes.system_info["users_share_sites"] CamaleonCms::User.where(site_id: self.id).destroy_all @@ -289,9 +300,10 @@ user = self.users.admin_scope.create({email: 'admin@local.com', username: 'admin', password: 'admin', password_confirmation: 'admin', first_name: 'Administrator'}) unless user.present? post = pt.add_post({title: title, slug: slug, content: content, user_id: user.id, status: 'published'}) @nav_menu.append_menu_item({label: title, type: 'post', link: post.id}) end end + get_anonymous_user end # assign all users to this new site def set_all_users CamaleonCms::User.all.each do |user| \ No newline at end of file