#-- # Copyright (c) 2012-2013 Damjan Rems # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ ######################################################################## # ######################################################################## class DcAtTheBeginningController < DcApplicationController before_filter :check_if_ok ######################################################################## # ######################################################################## def index end ######################################################################## # ######################################################################## def create if params['password1'] != params['password2'] flash[:error] = "Password doesn't match!" return render action: 'index' end if params['password1'].size < 8 flash[:error] = "Please be more creative. Password should be at least 8 characters long!" return render action: 'index' end # New role role = DcPolicyRole.new role.name = 'superadmin' role.system_name = 'superadmin' role.save # User usr = DcUser.new usr.username = params['username'] usr.password = params['password1'] usr.password_confirmation = params['password2'] usr.first_name = 'superadmin' usr.save # user role r = usr.dc_user_roles.new r.dc_policy_role_id = role._id r.save # cmsedit permission permission = DcPermission.new permission.table_name = 'Default permission' permission.is_default = true permission.save # r = permission.dc_policy_rules.new r.dc_policy_role_id = role._id r.permission = DcPermission::SUPERADMIN r.save # create login poll poll = DcPoll.new poll.name = 'login' poll.display = 'td' poll.operation = 'link' poll.parameters = '/dc_common/process_login' poll.title = 'Autocreated login form' poll.save # i = poll.dc_poll_items.new i.name = 'username' i.size = 15 i.text = 'Username' i.type = 'text_field' i.save # i = poll.dc_poll_items.new i.name = 'password' i.size = 15 i.text = 'Password' i.type = 'password_field' i.save # i = poll.dc_poll_items.new i.name = 'send' i.text = 'Login' i.type = 'submit_tag' i.save redirect_to '/cmsedit/login' end ######################################################################## # ######################################################################## def check_if_ok DcPermission.all.delete DcUserRole.all.delete DcUser.all.delete return dc_render_404('At the beginning: It can only be done in development!') if ENV["RAILS_ENV"] != 'development' return dc_render_404('At the beginning: Permissions table is not empty!') if DcPermission.all.size > 0 return dc_render_404('At the beginning: Roles table is not empty!') if DcUserRole.all.size > 0 return dc_render_404('At the beginning: Users table is not empty!') if DcUser.all.size > 0 end end