lib/crosstie/templates/user.rb in crosstie-0.0.6 vs lib/crosstie/templates/user.rb in crosstie-0.0.7

- old
+ new

@@ -4,19 +4,57 @@ # crosstie skeleton # ldap + # grant roles + + # grant normal + # username # authentication_token # authorization EOF end +# grant roles for the first user +inject_into_file "app/models/user.rb", after: "# grant roles\n" do +<<-EOF + after_create :grant_roles, if: Proc.new { + !Rails.env.test? && User.count == 1 + } + + def grant_roles + Role::USER_ROLES.each do |role| + self.grant role + end + end +EOF +end + +# grant normal role for signed up users +inject_into_file "app/models/user.rb", after: "# grant normal\n" do +<<-EOF + after_create :grant_normal, if: Proc.new { + ENV['GRANT_NORMAL'] + } + + def grant_normal + self.grant :normal + end +EOF +end + +append_file "config/application.yml", <<-EOF +#GRANT_NORMAL: true +EOF +run "cp config/application.yml config/application.yml.example" + + # add username to users inject_into_file "app/models/user.rb", after: "# username\n" do <<-EOF alias_attribute :name, :username EOF @@ -30,16 +68,23 @@ [ "app/views/devise/registrations/new.html.erb", "app/views/devise/registrations/edit.html.erb", ].each do |file| + gsub_file file, ", :autofocus => true", "" inject_into_file file, after: "<%= devise_error_messages! %>\n" do <<-EOF <div class="form-group"> <%= f.label :username %> - <%= f.text_field :username, class: 'form-control' %> + <%= f.text_field :username, autofocus: true, class: 'form-control' %> </div> EOF end end gsub_file "config/initializers/devise.rb", "# config.authentication_keys = [ :email ]", "config.authentication_keys = [ :username ]" + +# add tabindex to sign in +inject_into_file "app/views/devise/sessions/new.html.erb", ", tabindex: 1", after: "f.text_field :username" +inject_into_file "app/views/devise/sessions/new.html.erb", ", tabindex: 2", after: "f.password_field :password" +inject_into_file "app/views/devise/sessions/new.html.erb", ", tabindex: 3", after: "f.check_box :remember_me" +inject_into_file "app/views/devise/sessions/new.html.erb", ", tabindex: 4", after: "f.submit 'Sign in'"