From 24280f7a68bc678906567721423f445dd8e14156 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Tue, 11 Apr 2017 15:41:43 -0400 Subject: [PATCH] working on authentication --- app/models/user.rb | 4 +++ app/views/devise/passwords/new.html.haml | 25 +++++++++------- app/views/devise/shared/_links.html.haml | 6 ++-- app/views/layouts/_header.html.haml | 2 +- app/views/users/show.html.haml | 8 +++--- app/views/welcome/index.html.haml | 36 +++++++++++++++--------- db/seeds.rb | 17 ++++++++--- 7 files changed, 64 insertions(+), 34 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 69e24d25..2d2ce9d4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,4 +14,8 @@ class User < ApplicationRecord def admin?(school) schools.index(school).present? end + + def super_admin? + [1].index(id).present? + end end diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index 9add188d..e14f1900 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -1,10 +1,15 @@ -%h2 Forgot your password? -= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| - = devise_error_messages! - .field - = f.label :email - %br/ - = f.email_field :email, autofocus: true - .actions - = f.submit "Send me reset password instructions" -= render "devise/shared/links" +.row + .offset-sm-2.col-sm-8 + %h3 Forgot Your Password + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| + = devise_error_messages! + + .form-group + = f.label :email + %br/ + = f.email_field :email, autofocus: true, class: 'form-control' + + .form-group + = f.submit "Send Me Reset Password Instructions", class: 'btn btn-primary' + + = render "devise/shared/links" diff --git a/app/views/devise/shared/_links.html.haml b/app/views/devise/shared/_links.html.haml index 39ed8639..6ff12649 100644 --- a/app/views/devise/shared/_links.html.haml +++ b/app/views/devise/shared/_links.html.haml @@ -5,14 +5,16 @@ - if controller_name != 'sessions' Already have an account? +   = link_to "Log In", new_session_path(resource_name)         -- if devise_mapping.registerable? && controller_name != 'registrations' - Don't have an account? +-# if devise_mapping.registerable? && controller_name != 'registrations' + Don't have an account? +   = link_to "Sign Up", new_registration_path(resource_name)     diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index ac2b15f0..2be72317 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -7,4 +7,4 @@ = link_to 'Sign Out', destroy_user_session_path, rel: "nofollow", method: :delete, class: 'btn btn-small grey waves-effect waves-light ' - else = link_to 'Login', new_user_session_path, class: 'btn btn-small grey waves-effect waves-light ' - = link_to 'Register', new_user_registration_path, class: 'btn btn-small grey waves-effect waves-light ' + =# link_to 'Register', new_user_registration_path, class: 'btn btn-small grey waves-effect waves-light ' diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 2e7f658d..2b8c82ba 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -13,7 +13,7 @@ %thead{style: 'font-weight: bold;'} %th Name %th{colspan: 2} - - current_user.schools.each do |school| - %tr.school - %td= link_to school.name, school - %td= link_to('Admin', school_admin_path(school)) + - current_user.schools.each do |school| + %tr.school + %td= link_to school.name, school + %td= link_to('Admin', school_admin_path(school)) diff --git a/app/views/welcome/index.html.haml b/app/views/welcome/index.html.haml index fc3a0d73..2977b99f 100644 --- a/app/views/welcome/index.html.haml +++ b/app/views/welcome/index.html.haml @@ -1,17 +1,27 @@ -.row - .col-12 - %p= link_to "Create A New District", new_district_path +- if user_signed_in? && current_user.super_admin? + .row.super-admin + .col-12 + %p= link_to "Create A New District", new_district_path - %p= link_to "Create A New School", new_school_path + %p= link_to "Create A New School", new_school_path -.row.mt-3 - .col-6 - %h4 Districts - - @districts.each do |district| - %p= link_to district.name, district +- if user_signed_in? + .row.mt-3 + -# .col-6 + -# %h4 Districts + -# - @districts.each do |district| + -# %p= link_to district.name, district - .col-6 - %h4 Schools - - @schools.each do |school| - %p= link_to school.name, school + .col-6 + %h4 Schools + - current_user.schools.each do |school| + %p= link_to school.name, school + +- else + + .text-center.my-3.py-3 + %h3.my-3.py-3 + EdContext is currently in beta testing. + %p.py-3 + If you have an account, please sign in. diff --git a/db/seeds.rb b/db/seeds.rb index 58f51f71..0f5ee8ca 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,11 +10,20 @@ questions = Category.find_by_name('Family Subcategory').child_categories.map(&:questions).flatten QuestionList.create(name: 'Family Questions', question_id_array: questions.map(&:id)) +user = User.create(email: 'jared@edcontext.org', password: '123456') -cambridge = District.create(name: 'Cambridge Public Schools') -school = School.create(name: 'Graham & Parks', district: cambridge, description: 'A description of G&P') -recipient = school.recipients.create(name: 'Jared Cosulich', phone: '650-269-3205') -recipient_list = school.recipient_lists.create(name: 'Pilot Parent Test', recipient_id_array: [recipient.id]) +district = District.create(name: 'EdContext Test District') +school = School.create(name: 'EdContext Test School', district: district, description: 'A school used to test the EdContext System') +recipients = [ + school.recipients.create(name: 'Jared Cosulich', phone: '650-269-3205'), + school.recipients.create(name: 'Lauren Cosulich', phone: '6173522365'), + school.recipients.create(name: 'Jack Schneider', phone: '+1 267-968-2293'), + school.recipients.create(name: 'Lynisse Patin', phone: '19176566892'), + school.recipients.create(name: 'Khemenec Patin', phone: '(347) 534-6437'), +] +recipient_list = school.recipient_lists.create(name: 'Pilot Parent Test', recipient_id_array: recipients.map(&:id)) + +user.user_schools.create(school: school) # somerville = District.create(name: 'Somerville Public Schools') #