diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -10,6 +10,7 @@ end def login + MainController.layout 'login' reset_session end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,2 +1,27 @@ class UsersController < ApplicationController + + before_filter :authenticate + + verify :method => :post, :only => [:chg_passwd], + :redirect_to => { :action => :index } + + in_place_edit_for :user, :full_name + in_place_edit_for :user, :alias + + def index + @user = User.find(session[:user_id]) + end + + def chg_passwd + user = User.find(session[:user_id]) + user.password = params[:passwd] + user.password_confirmation = params[:passwd_verify] + if user.save + flash[:notice] = 'password changed' + else + flash[:notice] = 'Error: password changing failed' + end + redirect_to :action => 'index' + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,24 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + + def user_options + options = '' + user = User.find(session[:user_id]) + if user.admin? + options = options + ' ' + + (link_to_unless_current '[Problem admin]', + :controller => 'problems', :action => 'index') + options = options + ' ' + + (link_to_unless_current '[User admin]', + :controller => 'user_admin', :action => 'index') + end + options += link_to_unless_current '[Main]', + :controller => 'main', :action => 'list' + options += link_to_unless_current '[Settings]', + :controller => 'users', :action => 'index' + options = options + ' ' + + link_to('[Log out]', {:controller => 'main', :action => 'login'}) + options + end + end diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb --- a/app/helpers/main_helper.rb +++ b/app/helpers/main_helper.rb @@ -1,21 +1,5 @@ module MainHelper - def user_options - options = '' - user = User.find(session[:user_id]) - if user.admin? - options = options + ' ' + - link_to('[Problem admin]', - {:controller => 'problems', :action => 'index'}) - options = options + ' ' + - link_to('[User admin]', - {:controller => 'user_admin', :action => 'index'}) - end - options = options + ' ' + - link_to('[Log out]', {:controller => 'main', :action => 'login'}) - options - end - def format_short_time(time) now = Time.now st = '' diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -6,9 +6,16 @@
<%= flash[:notice] %>
+ <%= yield %> diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb new file mode 100644 --- /dev/null +++ b/app/views/layouts/login.html.erb @@ -0,0 +1,15 @@ + + + + + +<%= flash[:notice] %>
- -<%= yield %> - - - diff --git a/app/views/main/list.rhtml b/app/views/main/list.rhtml --- a/app/views/main/list.rhtml +++ b/app/views/main/list.rhtml @@ -1,10 +1,6 @@
-<%= text_field 'user', 'login' %>
-<%= text_field 'user', 'full_name' %>
-<%= password_field 'user', 'password' %>
-<%= password_field 'user', 'password_confirmation' %>
-<%= text_field 'user', 'alias' %>
<%= column.human_name %> | - <% end %> -|||
---|---|---|---|
<%=h user.send(column.name) %> | - <% end %> -<%= link_to 'Show', :action => 'show', :id => user %> | -<%= link_to 'Edit', :action => 'edit', :id => user %> | -<%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %> | -
- <%= column.human_name %>: <%=h @user.send(column.name) %> -
-<% end %> - -<%= link_to 'Edit', :action => 'edit', :id => @user %> | -<%= link_to 'Back', :action => 'list' %> diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,92 @@ +# This file is auto-generated from the current state of the database. Instead of editing this file, +# please use the migrations feature of ActiveRecord to incrementally modify your database, and +# then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your database schema. If you need +# to create the application database on another system, you should be using db:schema:load, not running +# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 11) do + + create_table "languages", :force => true do |t| + t.string "name", :limit => 10 + t.string "pretty_name" + t.string "ext", :limit => 10 + end + + create_table "problems", :force => true do |t| + t.string "name", :limit => 30 + t.string "full_name" + t.integer "full_score" + t.date "date_added" + t.boolean "available" + end + + create_table "rights", :force => true do |t| + t.string "name" + t.string "controller" + t.string "action" + end + + create_table "rights_roles", :id => false, :force => true do |t| + t.integer "right_id" + t.integer "role_id" + end + + add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" + + create_table "roles", :force => true do |t| + t.string "name" + end + + create_table "roles_users", :id => false, :force => true do |t| + t.integer "role_id" + t.integer "user_id" + end + + add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" + + create_table "sessions", :force => true do |t| + t.string "session_id" + t.text "data" + t.datetime "updated_at" + end + + add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" + add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" + + create_table "submissions", :force => true do |t| + t.integer "user_id" + t.integer "problem_id" + t.integer "language_id" + t.text "source" + t.binary "binary" + t.datetime "submitted_at" + t.datetime "compiled_at" + t.text "compiler_message" + t.datetime "graded_at" + t.integer "points" + t.text "grader_comment" + end + + add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" + + create_table "tasks", :force => true do |t| + t.integer "submission_id" + t.datetime "created_at" + end + + create_table "users", :force => true do |t| + t.string "login", :limit => 10 + t.string "full_name" + t.string "hashed_password" + t.string "salt", :limit => 5 + t.string "alias" + end + + add_index "users", ["login"], :name => "index_users_on_login", :unique => true + +end diff --git a/vendor/plugins/haml/init.rb b/vendor/plugins/haml/init.rb new file mode 100644 --- /dev/null +++ b/vendor/plugins/haml/init.rb @@ -0,0 +1,2 @@ +require 'haml' +Haml.init_rails(binding)