From 0b619ef453c0cef4db7e6207cb450b116d7ce2a0 Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Mon, 14 Apr 2014 14:15:31 +0200 Subject: [PATCH] Issue #201 fixing scenario add problem --- tutor/.gitignore | 1 - tutor/Gemfile | 4 +- tutor/Gemfile.lock | 11 + ...ms_by_tas.js.coffee => problems.js.coffee} | 0 ...lems_by_tas.css.scss => problems.css.scss} | 2 +- .../app/controllers/application_controller.rb | 6 +- ...s_controller.rb => problems_controller.rb} | 22 +- tutor/app/helpers/problems_by_tas_helper.rb | 2 - tutor/app/helpers/problems_helper.rb | 2 + tutor/app/models/lecturer.rb | 9 +- tutor/app/models/student.rb | 8 +- tutor/app/models/teaching_assistant.rb | 7 +- .../lecturers/confirmations/new.html.erb | 12 + .../mailer/confirmation_instructions.html.erb | 5 + .../reset_password_instructions.html.erb | 8 + .../mailer/unlock_instructions.html.erb | 7 + .../views/lecturers/passwords/edit.html.erb | 16 ++ .../views/lecturers/passwords/new.html.erb | 12 + .../lecturers/registrations/edit.html.erb | 29 ++ .../lecturers/registrations/new.html.erb | 18 ++ .../app/views/lecturers/sessions/new.html.erb | 17 ++ tutor/app/views/lecturers/shared/_links.erb | 25 ++ .../app/views/lecturers/unlocks/new.html.erb | 12 + .../edit.html.erb | 0 .../new.html.erb | 7 +- .../views/students/confirmations/new.html.erb | 12 + .../mailer/confirmation_instructions.html.erb | 5 + .../reset_password_instructions.html.erb | 8 + .../mailer/unlock_instructions.html.erb | 7 + .../views/students/passwords/edit.html.erb | 16 ++ .../app/views/students/passwords/new.html.erb | 12 + .../students/registrations/edit.html.erb | 29 ++ .../views/students/registrations/new.html.erb | 18 ++ .../app/views/students/sessions/new.html.erb | 17 ++ tutor/app/views/students/shared/_links.erb | 25 ++ tutor/app/views/students/unlocks/new.html.erb | 12 + .../confirmations/new.html.erb | 12 + .../mailer/confirmation_instructions.html.erb | 5 + .../reset_password_instructions.html.erb | 8 + .../mailer/unlock_instructions.html.erb | 7 + .../passwords/edit.html.erb | 16 ++ .../passwords/new.html.erb | 12 + .../registrations/edit.html.erb | 29 ++ .../registrations/new.html.erb | 18 ++ .../teaching_assistants/sessions/new.html.erb | 17 ++ .../teaching_assistants/shared/_links.erb | 25 ++ .../teaching_assistants/unlocks/new.html.erb | 12 + tutor/config/environments/development.rb | 3 + tutor/config/initializers/devise.rb | 256 ++++++++++++++++++ tutor/config/locales/devise.en.yml | 59 ++++ tutor/config/routes.rb | 87 ++---- tutor/db/development.sqlite3 | Bin 52224 -> 0 bytes tutor/db/schema.rb | 38 ++- .../controllers/problems_controller_test.rb | 7 + tutor/test/helpers/problems_helper_test.rb | 4 + 55 files changed, 923 insertions(+), 95 deletions(-) rename tutor/app/assets/javascripts/{problems_by_tas.js.coffee => problems.js.coffee} (100%) rename tutor/app/assets/stylesheets/{problems_by_tas.css.scss => problems.css.scss} (61%) rename tutor/app/controllers/{problems_by_tas_controller.rb => problems_controller.rb} (71%) delete mode 100644 tutor/app/helpers/problems_by_tas_helper.rb create mode 100644 tutor/app/helpers/problems_helper.rb create mode 100644 tutor/app/views/lecturers/confirmations/new.html.erb create mode 100644 tutor/app/views/lecturers/mailer/confirmation_instructions.html.erb create mode 100644 tutor/app/views/lecturers/mailer/reset_password_instructions.html.erb create mode 100644 tutor/app/views/lecturers/mailer/unlock_instructions.html.erb create mode 100644 tutor/app/views/lecturers/passwords/edit.html.erb create mode 100644 tutor/app/views/lecturers/passwords/new.html.erb create mode 100644 tutor/app/views/lecturers/registrations/edit.html.erb create mode 100644 tutor/app/views/lecturers/registrations/new.html.erb create mode 100644 tutor/app/views/lecturers/sessions/new.html.erb create mode 100644 tutor/app/views/lecturers/shared/_links.erb create mode 100644 tutor/app/views/lecturers/unlocks/new.html.erb rename tutor/app/views/{problems_by_tas => problems}/edit.html.erb (100%) rename tutor/app/views/{problems_by_tas => problems}/new.html.erb (87%) create mode 100644 tutor/app/views/students/confirmations/new.html.erb create mode 100644 tutor/app/views/students/mailer/confirmation_instructions.html.erb create mode 100644 tutor/app/views/students/mailer/reset_password_instructions.html.erb create mode 100644 tutor/app/views/students/mailer/unlock_instructions.html.erb create mode 100644 tutor/app/views/students/passwords/edit.html.erb create mode 100644 tutor/app/views/students/passwords/new.html.erb create mode 100644 tutor/app/views/students/registrations/edit.html.erb create mode 100644 tutor/app/views/students/registrations/new.html.erb create mode 100644 tutor/app/views/students/sessions/new.html.erb create mode 100644 tutor/app/views/students/shared/_links.erb create mode 100644 tutor/app/views/students/unlocks/new.html.erb create mode 100644 tutor/app/views/teaching_assistants/confirmations/new.html.erb create mode 100644 tutor/app/views/teaching_assistants/mailer/confirmation_instructions.html.erb create mode 100644 tutor/app/views/teaching_assistants/mailer/reset_password_instructions.html.erb create mode 100644 tutor/app/views/teaching_assistants/mailer/unlock_instructions.html.erb create mode 100644 tutor/app/views/teaching_assistants/passwords/edit.html.erb create mode 100644 tutor/app/views/teaching_assistants/passwords/new.html.erb create mode 100644 tutor/app/views/teaching_assistants/registrations/edit.html.erb create mode 100644 tutor/app/views/teaching_assistants/registrations/new.html.erb create mode 100644 tutor/app/views/teaching_assistants/sessions/new.html.erb create mode 100644 tutor/app/views/teaching_assistants/shared/_links.erb create mode 100644 tutor/app/views/teaching_assistants/unlocks/new.html.erb create mode 100644 tutor/config/initializers/devise.rb create mode 100644 tutor/config/locales/devise.en.yml delete mode 100644 tutor/db/development.sqlite3 create mode 100644 tutor/test/controllers/problems_controller_test.rb create mode 100644 tutor/test/helpers/problems_helper_test.rb diff --git a/tutor/.gitignore b/tutor/.gitignore index 49efaa07..c5f2f691 100644 --- a/tutor/.gitignore +++ b/tutor/.gitignore @@ -10,7 +10,6 @@ # Ignore the default SQLite database. /db/*.sqlite3 -!/db/development.sqlite3 /db/*.sqlite3-journal # Ignore all logfiles and tempfiles. diff --git a/tutor/Gemfile b/tutor/Gemfile index 6c21a290..fb9e982a 100644 --- a/tutor/Gemfile +++ b/tutor/Gemfile @@ -41,12 +41,14 @@ end gem 'unicorn' gem 'foreman' - # Use Capistrano for deployment # gem 'capistrano', group: :development # Use debugger # gem 'debugger', group: [:development, :test] +# User authentication +gem 'devise' + # Use composite primary keys in models gem 'composite_primary_keys', '~> 6.0.1' \ No newline at end of file diff --git a/tutor/Gemfile.lock b/tutor/Gemfile.lock index 2e129b10..fa0d2aac 100644 --- a/tutor/Gemfile.lock +++ b/tutor/Gemfile.lock @@ -27,6 +27,7 @@ GEM tzinfo (~> 0.3.37) arel (4.0.2) atomic (1.1.16) + bcrypt (3.1.7) builder (3.1.4) coffee-rails (4.0.1) coffee-script (>= 2.2.0) @@ -37,6 +38,12 @@ GEM coffee-script-source (1.7.0) composite_primary_keys (6.0.1) activerecord (>= 4.0.0) + devise (3.2.4) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 3.2.6, < 5) + thread_safe (~> 0.1) + warden (~> 1.2.3) dotenv (0.10.0) erubis (2.7.0) execjs (2.0.2) @@ -59,6 +66,7 @@ GEM mime-types (1.25.1) minitest (4.7.5) multi_json (1.9.2) + orm_adapter (0.5.0) polyglot (0.3.4) rack (1.5.2) rack-test (0.6.2) @@ -116,6 +124,8 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) + warden (1.2.3) + rack (>= 1.0) PLATFORMS ruby @@ -123,6 +133,7 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 4.0.0) composite_primary_keys (~> 6.0.1) + devise foreman jbuilder (~> 1.2) jquery-rails (~> 3.1.0) diff --git a/tutor/app/assets/javascripts/problems_by_tas.js.coffee b/tutor/app/assets/javascripts/problems.js.coffee similarity index 100% rename from tutor/app/assets/javascripts/problems_by_tas.js.coffee rename to tutor/app/assets/javascripts/problems.js.coffee diff --git a/tutor/app/assets/stylesheets/problems_by_tas.css.scss b/tutor/app/assets/stylesheets/problems.css.scss similarity index 61% rename from tutor/app/assets/stylesheets/problems_by_tas.css.scss rename to tutor/app/assets/stylesheets/problems.css.scss index 30f393b2..e08096e5 100644 --- a/tutor/app/assets/stylesheets/problems_by_tas.css.scss +++ b/tutor/app/assets/stylesheets/problems.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the problems_by_tas controller here. +// Place all the styles related to the problems controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/tutor/app/controllers/application_controller.rb b/tutor/app/controllers/application_controller.rb index d83690e1..27ef6a7e 100644 --- a/tutor/app/controllers/application_controller.rb +++ b/tutor/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - # Prevent CSRF attacks by raising an exception. - # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception end diff --git a/tutor/app/controllers/problems_by_tas_controller.rb b/tutor/app/controllers/problems_controller.rb similarity index 71% rename from tutor/app/controllers/problems_by_tas_controller.rb rename to tutor/app/controllers/problems_controller.rb index cf122008..219bac23 100644 --- a/tutor/app/controllers/problems_by_tas_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -1,4 +1,5 @@ -class ProblemsByTasController < ApplicationController +class ProblemsController < ApplicationController + # [Add Problem - 4.4] # Creates a new record to Problem Table # Parameters: @@ -11,10 +12,11 @@ def create if p.save redirect_to :action => "edit", :id => p.id else - flash.keep[:notice] = "Problem are missing paramaters" + flash.keep[:notice] = "Problem is missing paramaters" redirect_to :back end end + # [Add Problem - 4.4] # Passes the input of the form as paramaters for create action to use it # Parameters: @@ -25,6 +27,7 @@ def create def permitCreate params.require(:Problem).permit(:title , :description) end + # [Edit Problem - 4.5] # Shows the problem's title and description (Further development is in Sprint 1) # Parameters: @@ -34,6 +37,19 @@ def permitCreate def edit @problem = Problem.find_by_id(params[:id]) end + + # [Edit Problem - 4.5] + # Checks if the user signed in is a lecturer or a TA + # Parameters: + # none + # Returns: Redirects to add problem page on success, renders error 404 on failure + # Author: Abdullrahman Elhusseny def new + if lecturer_signed_in? || teaching_assistant_signed_in? + render ('new') + else + render ('public/404') + end end -end + +end \ No newline at end of file diff --git a/tutor/app/helpers/problems_by_tas_helper.rb b/tutor/app/helpers/problems_by_tas_helper.rb deleted file mode 100644 index 58021886..00000000 --- a/tutor/app/helpers/problems_by_tas_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ProblemsByTasHelper -end diff --git a/tutor/app/helpers/problems_helper.rb b/tutor/app/helpers/problems_helper.rb new file mode 100644 index 00000000..6989835e --- /dev/null +++ b/tutor/app/helpers/problems_helper.rb @@ -0,0 +1,2 @@ +module ProblemsHelper +end diff --git a/tutor/app/models/lecturer.rb b/tutor/app/models/lecturer.rb index 5306ff95..28305e7b 100644 --- a/tutor/app/models/lecturer.rb +++ b/tutor/app/models/lecturer.rb @@ -1,4 +1,8 @@ class Lecturer < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable #Validations @@ -6,7 +10,7 @@ class Lecturer < ActiveRecord::Base has_one :user, as: :sub has_and_belongs_to_many :courses, join_table: "courses_lecturers" - has_and_belongs_to_many :worked_with, class_name:"TeachingAssistant",join_table: "lecturers_teaching_assistants" + has_and_belongs_to_many :worked_with, class_name:"TeachingAssistant", join_table: "lecturers_teaching_assistants" has_many :topics @@ -16,7 +20,4 @@ class Lecturer < ActiveRecord::Base #Scoops #Methods - - - end diff --git a/tutor/app/models/student.rb b/tutor/app/models/student.rb index 19a56b67..100b068b 100644 --- a/tutor/app/models/student.rb +++ b/tutor/app/models/student.rb @@ -1,4 +1,8 @@ class Student < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable #Validations @@ -21,6 +25,4 @@ class Student < ActiveRecord::Base #Scoops #Methods - - -end +end \ No newline at end of file diff --git a/tutor/app/models/teaching_assistant.rb b/tutor/app/models/teaching_assistant.rb index 9145d872..48a32a6a 100644 --- a/tutor/app/models/teaching_assistant.rb +++ b/tutor/app/models/teaching_assistant.rb @@ -1,4 +1,8 @@ class TeachingAssistant < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable #Validations @@ -8,7 +12,4 @@ class TeachingAssistant < ActiveRecord::Base has_and_belongs_to_many :courses, join_table: "courses_teaching_assistants" #Scoops #Methods - - - end diff --git a/tutor/app/views/lecturers/confirmations/new.html.erb b/tutor/app/views/lecturers/confirmations/new.html.erb new file mode 100644 index 00000000..896c821a --- /dev/null +++ b/tutor/app/views/lecturers/confirmations/new.html.erb @@ -0,0 +1,12 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Resend confirmation instructions" %>
+<% end %> + +<%= render "lecturers/shared/links" %> diff --git a/tutor/app/views/lecturers/mailer/confirmation_instructions.html.erb b/tutor/app/views/lecturers/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/tutor/app/views/lecturers/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/tutor/app/views/lecturers/mailer/reset_password_instructions.html.erb b/tutor/app/views/lecturers/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/tutor/app/views/lecturers/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/tutor/app/views/lecturers/mailer/unlock_instructions.html.erb b/tutor/app/views/lecturers/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/tutor/app/views/lecturers/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/tutor/app/views/lecturers/passwords/edit.html.erb b/tutor/app/views/lecturers/passwords/edit.html.erb new file mode 100644 index 00000000..3ab4deb8 --- /dev/null +++ b/tutor/app/views/lecturers/passwords/edit.html.erb @@ -0,0 +1,16 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + <%= f.hidden_field :reset_password_token %> + +
<%= f.label :password, "New password" %>
+ <%= f.password_field :password, autofocus: true, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Change my password" %>
+<% end %> + +<%= render "lecturers/shared/links" %> diff --git a/tutor/app/views/lecturers/passwords/new.html.erb b/tutor/app/views/lecturers/passwords/new.html.erb new file mode 100644 index 00000000..16789b88 --- /dev/null +++ b/tutor/app/views/lecturers/passwords/new.html.erb @@ -0,0 +1,12 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Send me reset password instructions" %>
+<% end %> + +<%= render "lecturers/shared/links" %> diff --git a/tutor/app/views/lecturers/registrations/edit.html.erb b/tutor/app/views/lecturers/registrations/edit.html.erb new file mode 100644 index 00000000..808d62c9 --- /dev/null +++ b/tutor/app/views/lecturers/registrations/edit.html.erb @@ -0,0 +1,29 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
<%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off" %>
+ +
<%= f.submit "Update" %>
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/tutor/app/views/lecturers/registrations/new.html.erb b/tutor/app/views/lecturers/registrations/new.html.erb new file mode 100644 index 00000000..7a7eea86 --- /dev/null +++ b/tutor/app/views/lecturers/registrations/new.html.erb @@ -0,0 +1,18 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Sign up" %>
+<% end %> + +<%= render "lecturers/shared/links" %> diff --git a/tutor/app/views/lecturers/sessions/new.html.erb b/tutor/app/views/lecturers/sessions/new.html.erb new file mode 100644 index 00000000..72eb9c8e --- /dev/null +++ b/tutor/app/views/lecturers/sessions/new.html.erb @@ -0,0 +1,17 @@ +

Sign in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %>
+ + <% if devise_mapping.rememberable? -%> +
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
+ <% end -%> + +
<%= f.submit "Sign in" %>
+<% end %> + +<%= render "lecturers/shared/links" %> diff --git a/tutor/app/views/lecturers/shared/_links.erb b/tutor/app/views/lecturers/shared/_links.erb new file mode 100644 index 00000000..d84bdde9 --- /dev/null +++ b/tutor/app/views/lecturers/shared/_links.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Sign in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> diff --git a/tutor/app/views/lecturers/unlocks/new.html.erb b/tutor/app/views/lecturers/unlocks/new.html.erb new file mode 100644 index 00000000..308bb295 --- /dev/null +++ b/tutor/app/views/lecturers/unlocks/new.html.erb @@ -0,0 +1,12 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Resend unlock instructions" %>
+<% end %> + +<%= render "lecturers/shared/links" %> diff --git a/tutor/app/views/problems_by_tas/edit.html.erb b/tutor/app/views/problems/edit.html.erb similarity index 100% rename from tutor/app/views/problems_by_tas/edit.html.erb rename to tutor/app/views/problems/edit.html.erb diff --git a/tutor/app/views/problems_by_tas/new.html.erb b/tutor/app/views/problems/new.html.erb similarity index 87% rename from tutor/app/views/problems_by_tas/new.html.erb rename to tutor/app/views/problems/new.html.erb index cdf066a6..b1dbe5cf 100644 --- a/tutor/app/views/problems_by_tas/new.html.erb +++ b/tutor/app/views/problems/new.html.erb @@ -1,4 +1,4 @@ -

Edit Problem Page

+

Add a problem


- <% if flash[:notice] %> + + <% if flash[:notice] %>
<%= flash[:notice] %>
<% end %> \ No newline at end of file diff --git a/tutor/app/views/students/confirmations/new.html.erb b/tutor/app/views/students/confirmations/new.html.erb new file mode 100644 index 00000000..31961fcf --- /dev/null +++ b/tutor/app/views/students/confirmations/new.html.erb @@ -0,0 +1,12 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Resend confirmation instructions" %>
+<% end %> + +<%= render "students/shared/links" %> diff --git a/tutor/app/views/students/mailer/confirmation_instructions.html.erb b/tutor/app/views/students/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/tutor/app/views/students/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/tutor/app/views/students/mailer/reset_password_instructions.html.erb b/tutor/app/views/students/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/tutor/app/views/students/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/tutor/app/views/students/mailer/unlock_instructions.html.erb b/tutor/app/views/students/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/tutor/app/views/students/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/tutor/app/views/students/passwords/edit.html.erb b/tutor/app/views/students/passwords/edit.html.erb new file mode 100644 index 00000000..b0fc0955 --- /dev/null +++ b/tutor/app/views/students/passwords/edit.html.erb @@ -0,0 +1,16 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + <%= f.hidden_field :reset_password_token %> + +
<%= f.label :password, "New password" %>
+ <%= f.password_field :password, autofocus: true, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Change my password" %>
+<% end %> + +<%= render "students/shared/links" %> diff --git a/tutor/app/views/students/passwords/new.html.erb b/tutor/app/views/students/passwords/new.html.erb new file mode 100644 index 00000000..fda12c26 --- /dev/null +++ b/tutor/app/views/students/passwords/new.html.erb @@ -0,0 +1,12 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Send me reset password instructions" %>
+<% end %> + +<%= render "students/shared/links" %> diff --git a/tutor/app/views/students/registrations/edit.html.erb b/tutor/app/views/students/registrations/edit.html.erb new file mode 100644 index 00000000..808d62c9 --- /dev/null +++ b/tutor/app/views/students/registrations/edit.html.erb @@ -0,0 +1,29 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
<%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off" %>
+ +
<%= f.submit "Update" %>
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/tutor/app/views/students/registrations/new.html.erb b/tutor/app/views/students/registrations/new.html.erb new file mode 100644 index 00000000..b9e8446f --- /dev/null +++ b/tutor/app/views/students/registrations/new.html.erb @@ -0,0 +1,18 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Sign up" %>
+<% end %> + +<%= render "students/shared/links" %> diff --git a/tutor/app/views/students/sessions/new.html.erb b/tutor/app/views/students/sessions/new.html.erb new file mode 100644 index 00000000..ca7345fc --- /dev/null +++ b/tutor/app/views/students/sessions/new.html.erb @@ -0,0 +1,17 @@ +

Sign in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %>
+ + <% if devise_mapping.rememberable? -%> +
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
+ <% end -%> + +
<%= f.submit "Sign in" %>
+<% end %> + +<%= render "students/shared/links" %> diff --git a/tutor/app/views/students/shared/_links.erb b/tutor/app/views/students/shared/_links.erb new file mode 100644 index 00000000..d84bdde9 --- /dev/null +++ b/tutor/app/views/students/shared/_links.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Sign in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> diff --git a/tutor/app/views/students/unlocks/new.html.erb b/tutor/app/views/students/unlocks/new.html.erb new file mode 100644 index 00000000..292c2896 --- /dev/null +++ b/tutor/app/views/students/unlocks/new.html.erb @@ -0,0 +1,12 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Resend unlock instructions" %>
+<% end %> + +<%= render "students/shared/links" %> diff --git a/tutor/app/views/teaching_assistants/confirmations/new.html.erb b/tutor/app/views/teaching_assistants/confirmations/new.html.erb new file mode 100644 index 00000000..619021b0 --- /dev/null +++ b/tutor/app/views/teaching_assistants/confirmations/new.html.erb @@ -0,0 +1,12 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Resend confirmation instructions" %>
+<% end %> + +<%= render "teaching_assistants/shared/links" %> diff --git a/tutor/app/views/teaching_assistants/mailer/confirmation_instructions.html.erb b/tutor/app/views/teaching_assistants/mailer/confirmation_instructions.html.erb new file mode 100644 index 00000000..dc55f64f --- /dev/null +++ b/tutor/app/views/teaching_assistants/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/tutor/app/views/teaching_assistants/mailer/reset_password_instructions.html.erb b/tutor/app/views/teaching_assistants/mailer/reset_password_instructions.html.erb new file mode 100644 index 00000000..f667dc12 --- /dev/null +++ b/tutor/app/views/teaching_assistants/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/tutor/app/views/teaching_assistants/mailer/unlock_instructions.html.erb b/tutor/app/views/teaching_assistants/mailer/unlock_instructions.html.erb new file mode 100644 index 00000000..41e148bf --- /dev/null +++ b/tutor/app/views/teaching_assistants/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/tutor/app/views/teaching_assistants/passwords/edit.html.erb b/tutor/app/views/teaching_assistants/passwords/edit.html.erb new file mode 100644 index 00000000..1e82eb0e --- /dev/null +++ b/tutor/app/views/teaching_assistants/passwords/edit.html.erb @@ -0,0 +1,16 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + <%= f.hidden_field :reset_password_token %> + +
<%= f.label :password, "New password" %>
+ <%= f.password_field :password, autofocus: true, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Change my password" %>
+<% end %> + +<%= render "teaching_assistants/shared/links" %> diff --git a/tutor/app/views/teaching_assistants/passwords/new.html.erb b/tutor/app/views/teaching_assistants/passwords/new.html.erb new file mode 100644 index 00000000..75a7de9c --- /dev/null +++ b/tutor/app/views/teaching_assistants/passwords/new.html.erb @@ -0,0 +1,12 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Send me reset password instructions" %>
+<% end %> + +<%= render "teaching_assistants/shared/links" %> diff --git a/tutor/app/views/teaching_assistants/registrations/edit.html.erb b/tutor/app/views/teaching_assistants/registrations/edit.html.erb new file mode 100644 index 00000000..808d62c9 --- /dev/null +++ b/tutor/app/views/teaching_assistants/registrations/edit.html.erb @@ -0,0 +1,29 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
<%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off" %>
+ +
<%= f.submit "Update" %>
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/tutor/app/views/teaching_assistants/registrations/new.html.erb b/tutor/app/views/teaching_assistants/registrations/new.html.erb new file mode 100644 index 00000000..eee37bb1 --- /dev/null +++ b/tutor/app/views/teaching_assistants/registrations/new.html.erb @@ -0,0 +1,18 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Sign up" %>
+<% end %> + +<%= render "teaching_assistants/shared/links" %> diff --git a/tutor/app/views/teaching_assistants/sessions/new.html.erb b/tutor/app/views/teaching_assistants/sessions/new.html.erb new file mode 100644 index 00000000..33433ed0 --- /dev/null +++ b/tutor/app/views/teaching_assistants/sessions/new.html.erb @@ -0,0 +1,17 @@ +

Sign in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %>
+ + <% if devise_mapping.rememberable? -%> +
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
+ <% end -%> + +
<%= f.submit "Sign in" %>
+<% end %> + +<%= render "teaching_assistants/shared/links" %> diff --git a/tutor/app/views/teaching_assistants/shared/_links.erb b/tutor/app/views/teaching_assistants/shared/_links.erb new file mode 100644 index 00000000..d84bdde9 --- /dev/null +++ b/tutor/app/views/teaching_assistants/shared/_links.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Sign in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> diff --git a/tutor/app/views/teaching_assistants/unlocks/new.html.erb b/tutor/app/views/teaching_assistants/unlocks/new.html.erb new file mode 100644 index 00000000..3d226757 --- /dev/null +++ b/tutor/app/views/teaching_assistants/unlocks/new.html.erb @@ -0,0 +1,12 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %>
+ +
<%= f.submit "Resend unlock instructions" %>
+<% end %> + +<%= render "teaching_assistants/shared/links" %> diff --git a/tutor/config/environments/development.rb b/tutor/config/environments/development.rb index 0c7a53a1..88d4c8c3 100644 --- a/tutor/config/environments/development.rb +++ b/tutor/config/environments/development.rb @@ -26,4 +26,7 @@ # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true + + # Configuring Devise mailer in Development environment + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } end diff --git a/tutor/config/initializers/devise.rb b/tutor/config/initializers/devise.rb new file mode 100644 index 00000000..b34152e6 --- /dev/null +++ b/tutor/config/initializers/devise.rb @@ -0,0 +1,256 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # config.secret_key = '3b6812af72cd3ef10caa3ae11bc1b87ed9a110496e837db6ecb8fdca49c6310d575cface3b96cf11c4b6b69ac7d5689b7edab11de0d631af50ad924a5875317d' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [ :email ] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [ :email ] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [ :email ] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If http headers should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 10. If + # using other encryptors, it sets how many times you want the password re-encrypted. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # encryptor), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 10 + + # Setup a pepper to generate the encrypted password. + # config.pepper = '6253200f58d75f4a163ade86b69e7319dde8f6554b5bb026217b78e471dcde09b289da4c3ae19ff4f582da1133274e953acb38c78dd5960baee1ca7270ebee60' + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [ :email ] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 8..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + # config.email_regexp = /\A[^@]+@[^@]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # If true, expires auth token on session timeout. + # config.expire_auth_token_on_timeout = false + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = false + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # ==> Configuration for :encryptable + # Allow you to use another encryption algorithm besides bcrypt (default). You can use + # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, + # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) + # and :restful_authentication_sha1 (then you should set stretches to 10, and copy + # REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + config.scoped_views = true + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using omniauth, Devise cannot automatically set Omniauth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' +end diff --git a/tutor/config/locales/devise.en.yml b/tutor/config/locales/devise.en.yml new file mode 100644 index 00000000..abccdb08 --- /dev/null +++ b/tutor/config/locales/devise.en.yml @@ -0,0 +1,59 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your account was successfully confirmed." + send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid email or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account will be locked." + not_found_in_database: "Invalid email or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your account before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock Instructions" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password was changed successfully. You are now signed in." + updated_not_active: "Your password was changed successfully." + registrations: + destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." + updated: "You updated your account successfully." + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index 02dc56da..8badae52 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -1,78 +1,28 @@ Tutor::Application.routes.draw do - resources :tracks do - post 'getProblems' , on: :member - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". + devise_for :teaching_assistants + devise_for :students + devise_for :lecturers - # You can have the root of your site routed with "root" - root 'site#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - resources :problems_by_tas - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - resources :tracks do - post 'getProblems' , on: :member - end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". - + # You can have the root of your site routed with "root" root 'site#index' - + + resources :tracks do + post 'getProblems' , on: :member + end + resources :problems + # Example of regular route: # get 'products/:id' => 'catalog#view' - + # Example of named route that can be invoked with purchase_url(id: product.id) # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - + # Example resource route (maps HTTP verbs to controller actions automatically): # resources :products - + # Example resource route with options: # resources :products do # member do @@ -84,13 +34,13 @@ # get 'sold' # end # end - + # Example resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end - + # Example resource route with more complex sub-resources: # resources :products do # resources :comments @@ -98,19 +48,18 @@ # get 'recent', on: :collection # end # end - + # Example resource route with concerns: # concern :toggleable do # post 'toggle' # end # resources :posts, concerns: :toggleable # resources :photos, concerns: :toggleable - + # Example resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end -end - +end \ No newline at end of file diff --git a/tutor/db/development.sqlite3 b/tutor/db/development.sqlite3 deleted file mode 100644 index 99634067990ce7ed3c6651b99efc07592a611548..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 52224 zcmeHQ&2Jmm5#Ps^yq5g!I9|(&q7@xUW*u3UWu@pLO;tq|1WU5xNJx#eC068$+LYu{ z`CDl@9g+750;YW%h2*M=%pN0S4-vpfWc^B|WeCN$h zCxxl+GW}3GD1O80+!g;P{#X3B_)qa4;&reaBHyMqQ-2aa=yl6Z?{-ZWc9~+tx~IwxkzK)zXbJjSx}`j~3_G7nSw-AFnJb=}386xtZS8ObU(D z%C2hWwpH`y-MP7pvi4wIS=(4y$=Fg#lHZ0gr}c7Pds;2)J5?D?UHqw%Zq_`lJXkw`zl?oel;oiyVn5;1tND^%rp~c1D5pbY!s+=m486X%wD?GQ z_-J``{?TLQ{^Db0eq;T?@*1>SU0ee}U18r;(m7L8EiIo_t+bMdGfOXNK(1EUMUb3% z*mp|4b&EW9l(AEUbdxOA0G@JAqruDm0E3~zn`IRSftDFt>6hg3aZ(d`pE)D1WwpF+ z87B3gp9=Jr_7`N=|4It8=`ZX!qs;#Mg;haVB@5(v z>Pzun8`f`ANs@<$$==(p)K!y${Tck@bXZPKO(Y=uCIl^!eJ9~-5FtL(R5PvUWlJk) zCRCzYNu!n)pyh!@Q?IalLt3%4r&fz!aQpme=YDhFFLk!4<*cd+w+&bR2H{LB5{+_( ziPI>{EYs!QZ+~9jvE>>2;eaGpr%7#q-;DSn8{r~rlwBh9l2yz3Is&WS%2pj>@A_Ok!d`K3tT=$(noaOsJ|oFH zQ=~>>@b$)s!rSQ66W*(P{sqAG>h9NX5L&NAP+DdL4r)xe46}cH|JTMn51S$aJ&XX$ z|3UljVFe=Vh(H?%;O~DM;9*llpvMuw-~S$0AhM4Lw1EKr{cw#8JBi*qRK+i#tfKDvvJYr zXrm^9>1*dCc@!A`kO!vM=NFt;FJ8Pk+7G=H8+xv{3`Ue=+6S43;BvGMk2Blyd0=gn z*q?Ar^V(*$0Iy_d{p4~GuR5I#(9!pk_Qx0a>zloChclh#s-R$aJF;o0W}fE5gjYhG zhRYLiZ0S}p`ua-ES^6$}rJ7bY4Wp>3W#!$)pUiKptSggSlk7beSFr!vz=$opoyF(> zL%C&OCx}2#B7o2TJ*hTi8WA`Y1knBu1xD-y5$H(-(EfW;ZOAkta3}~c`xk{T1mO$v zTk)Mk=`v|2wbK_RS(eG3!2>Z6YO^RmTnPqTI4x0-1#*9>T7WQ%o8@agtH6aDSz)m& zNMo<(+rl-iZkBW>76gG7NFom84VNI{xCn`}^oeGMA}|mg+}aA!T8YZ+Om^j}wjkJKA~hk79l1ny`V~pO0UlJr%~@IT=FNIu z8jbUTuDSkFa6an#e7&`kxw3B`&HX6wRlSzXt;*P+T#@9N8RF)Mlr(GG$iwW}GPO*V z#VMkc>p_PuS|O3E?sgOFv3D>YVLyG<$&nf5Zm!D(xZN-j8=@kf_zl8vtn`iYM8emb zNBsOwivF{!k~}#{YR-BJ{*h?l;-zUUB5B(4)#st2neS^}$Cl>BZ!3sJQhX~O6K zBfsO}fQUfXAb|GYHL5^H5P>5{0PX+CA;$p`fv!OS?Z0bOfs7ymM~(oqe^K~a5WXgV zNd581hi`L0yCOSrxidU2RW>ZhPRa3QKC>);g+?hO!7xp>|tvV^(Y)wL&-EfvTTY#P}+;dybPz*Ln+ zvZ6St?Ub9^{UJ#n86ltQ4ggMAjJn}5s)S&0ixVLcKPfM6y+~Tk!D^-y7DTnQQpJLR zUjwKu_#(nWkg;V=uw{v8*`i+31BgScIrqyD%ozV`^A>{55rGqo06zbpVCAFeCmsQ` z{}cZeKmblK0?hvVgs%kQEAso)JK{i>Lt#I?F0tJt_9nUWXKFd41T#Ni+X=R_N9b}a z=n95P6M2Nqk}&u(^dZ-*K3>of_Rq~|X{yQPVc1gQ7O{WM6Qy|XSHNvM{?R}q1LXBe8*)7I984pTRuaHn4wpoQ6{wZqZg0<}r8Gu)BRRci; z-(=M4*ER;PZb6!Nsl-fi6b??Z3+vgzO;#9Yg@_zk}dn z*N8xuBf#uGCF}^o4*A=Wuv#m;&iAMNEaSvk*!(5Rvl!?^D8j;v5`|Y{=f}n8;=JS) zZD3AY{L(cXl1M&LE1{iF)1y35<~Op7w6j;Hw=Lw&FxpP>vBrB#%~gxmvk0su^&lpB#Qm~>_RAiM5Bz!5wzH}5_y0)ldN>Fo(3J?F z{dc8WkSRpqNDyH5FABE>;Wqh?NDdluZ(fn)*;(?r^Y9*BgpkINGQkJUm>S3WnX_Q3 z`6}DPCA(!BrN~2Oqd5Gy8D3&@pLH%R~bFmPfb2wr?5 z0W6^ksTJU-Sj-`5Od^Qg=*PcCjlXUS`~TqY|3UXWEJp;6F9K-)$5*!~86t2H0%-pS zA%x|K!0|KFF@?=4_}(FGjZm1k?WatI zJj+OhL|$f5+tpypj)v3dy(MD%=QgO^xefW&tppJ4wKpW0&X8I^pNPN@*{FaNemoe;okLxGOc=$#lv zC0ot2NeDpSf(0v_cajYaHCq+Hh0m|dxS&WY%EbKt4&E8CYeb;S5y0pFE>{q;hX`~K z0kr=Pf{R@v0$q*(v;P#S38~+~0smeC0=4Utk~}v@_CDa=C*+{&Ds1%N-(4h*HXHOz zC$>WfSK$jr!e-wW%TmS$7 diff --git a/tutor/db/schema.rb b/tutor/db/schema.rb index 1cf138b0..f4500461 100644 --- a/tutor/db/schema.rb +++ b/tutor/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140326150549) do +ActiveRecord::Schema.define(version: 20140413181651) do create_table "admins", force: true do |t| t.datetime "created_at" @@ -98,8 +98,20 @@ t.string "lecturer_type" t.datetime "created_at" t.datetime "updated_at" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" end + add_index "lecturers", ["email"], name: "index_lecturers_on_email", unique: true + add_index "lecturers", ["reset_password_token"], name: "index_lecturers_on_reset_password_token", unique: true + create_table "lecturers_teaching_assistants", id: false, force: true do |t| t.integer "teaching_assistant_id", null: false t.integer "lecturer_id", null: false @@ -226,8 +238,20 @@ t.string "student_type" t.datetime "created_at" t.datetime "updated_at" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" end + add_index "students", ["email"], name: "index_students_on_email", unique: true + add_index "students", ["reset_password_token"], name: "index_students_on_reset_password_token", unique: true + create_table "teaching_assistants", force: true do |t| t.string "name" t.string "email" @@ -243,8 +267,20 @@ t.string "department" t.datetime "created_at" t.datetime "updated_at" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" end + add_index "teaching_assistants", ["email"], name: "index_teaching_assistants_on_email", unique: true + add_index "teaching_assistants", ["reset_password_token"], name: "index_teaching_assistants_on_reset_password_token", unique: true + create_table "test_cases", force: true do |t| t.string "input" t.string "output" diff --git a/tutor/test/controllers/problems_controller_test.rb b/tutor/test/controllers/problems_controller_test.rb new file mode 100644 index 00000000..159ed3a0 --- /dev/null +++ b/tutor/test/controllers/problems_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProblemsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/tutor/test/helpers/problems_helper_test.rb b/tutor/test/helpers/problems_helper_test.rb new file mode 100644 index 00000000..1de2c21a --- /dev/null +++ b/tutor/test/helpers/problems_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ProblemsHelperTest < ActionView::TestCase +end