Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,451 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
# coding: utf-8 | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
layout 'server' | ||
filter_parameter_logging :password | ||
helper_method :current_user | ||
|
||
def auth_current_user | ||
unless current_user | ||
flash[:notice] = "你必须登陆后才能访问此页面" | ||
redirect_to login_path | ||
else | ||
|
||
end | ||
end | ||
|
||
private | ||
|
||
def current_user_session | ||
return @current_user_session if defined?(@current_user_session) | ||
@current_user_session = UserSession.find | ||
end | ||
|
||
def current_user | ||
return @current_user if defined?(@current_user) | ||
@current_user = current_user_session && current_user_session.record | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# coding: utf-8 | ||
class UserSessionsController < ApplicationController | ||
before_filter :auth_current_user,:except => [:new,:create] | ||
def new | ||
@user_session = UserSession.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @user_session } | ||
end | ||
end | ||
|
||
# POST /user_sessions | ||
# POST /user_sessions.xml | ||
def create | ||
@user_session = UserSession.new(params[:user_session]) | ||
|
||
respond_to do |format| | ||
if @user_session.save | ||
format.html { redirect_to(servers_path, :notice => '登陆成功,请继续操作。。。') } | ||
format.xml { render :xml => @user_session, :status => :created, :location => @user_session } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @user_session.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /user_sessions/1 | ||
# PUT /user_sessions/1.xml | ||
def update | ||
@user_session = UserSession.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @user_session.update_attributes(params[:user_session]) | ||
format.html { redirect_to(@user_session, :notice => 'User session was successfully updated.') } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @user_session.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /user_sessions/1 | ||
# DELETE /user_sessions/1.xml | ||
def destroy | ||
@user_session = UserSession.find | ||
@user_session.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(new_user_session_path) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# coding: utf-8 | ||
class UsersController < ApplicationController | ||
layout 'server' | ||
before_filter :auth_current_user,:except => [:new,:create] | ||
# GET /users | ||
# GET /users.xml | ||
def index | ||
@users = User.paginate(:page => params[:page],:per_page => 10) | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.xml { render :xml => @users } | ||
end | ||
end | ||
|
||
# GET /users/1 | ||
# GET /users/1.xml | ||
def show | ||
@user = User.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @user } | ||
end | ||
end | ||
|
||
# GET /users/new | ||
# GET /users/new.xml | ||
def new | ||
@user = User.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @user } | ||
end | ||
end | ||
|
||
# GET /users/1/edit | ||
def edit | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
# POST /users | ||
# POST /users.xml | ||
def create | ||
@user = User.new(params[:user]) | ||
if @user.save | ||
#format.html { redirect_to(@user, :notice => 'User was successfully created.') } | ||
flash[:notice] = "注册成功,请登陆..." | ||
redirect_to login_path | ||
else | ||
render :action => "new" | ||
end | ||
end | ||
|
||
# PUT /users/1 | ||
# PUT /users/1.xml | ||
def update | ||
@user = User.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @user.update_attributes(params[:user]) | ||
format.html { redirect_to(@user, :notice => 'User was successfully updated.') } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @user.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /users/1 | ||
# DELETE /users/1.xml | ||
def destroy | ||
@user = User.find(params[:id]) | ||
@user.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(users_url) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module UserSessionsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module UsersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class User < ActiveRecord::Base | ||
acts_as_authentic | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class UserSession < Authlogic::Session::Base | ||
attr:login_name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= form_for(@user_session) do |f| %> | ||
<% if @user_session.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@user_session.errors.count, "error") %> prohibited this user_session from being saved:</h2> | ||
|
||
<ul> | ||
<% @user_session.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing user_session</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @user_session %> | | ||
<%= link_to 'Back', user_sessions_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h1>Listing user_sessions</h1> | ||
|
||
<table> | ||
<tr> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @user_sessions.each do |user_session| %> | ||
<tr> | ||
<td><%= link_to 'Show', user_session %></td> | ||
<td><%= link_to 'Edit', edit_user_session_path(user_session) %></td> | ||
<td><%= link_to 'Destroy', user_session, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New User session', new_user_session_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="block"> | ||
<div class="secondary-navigation"> | ||
</div> | ||
<div class="content"> | ||
<h2 class="title">用户登陆</h2> | ||
<div class="inner"> | ||
<% form_for @user_session do |f| %> | ||
<%= f.error_messages %> | ||
<p> | ||
<%= f.label :邮箱 %><br /> | ||
<%= f.text_field :email %> | ||
</p> | ||
<p> | ||
<%= f.label :密码 %><br /> | ||
<%= f.password_field :password %> | ||
</p> | ||
<p><%= f.submit "登陆->" %></p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
|
||
<%= link_to 'Edit', edit_user_session_path(@user_session) %> | | ||
<%= link_to 'Back', user_sessions_path %> |
Oops, something went wrong.