Commit 59155025 authored by 神楽坂玲奈's avatar 神楽坂玲奈

注册登录 初步

git-svn-id: http://glupx.googlecode.com/svn/trunk/Reliz@42 189f022a-1064-8ae2-3e6f-c4a67275c50b
parent e9cd6941
......@@ -8,7 +8,14 @@ class ApplicationController < ActionController::Base
@actions = ["warning: no actions here"] unless @actions
end
def check_user
@correct_user = User.find_by_name "admin"
if session[:user_id]
@correct_user = User.find session[:user_id]
end
unless @correct_user
@correct_user = User.new
@correct_user.name = '游客'
end
p @correct_user
end
def set_language
request_language = request.env['HTTP_ACCEPT_LANGUAGE']
......
......@@ -39,9 +39,23 @@ class BoardsController < ApplicationController
# GET /boards/1/edit
def edit
@board = Board.find(params[:id])
@actions = [@board, :edit_board]
@page=1
@topics = @board.topics.all(:offset => 20*@page-20, :limit => 20, :order => [:displayorder, :id])
end
def edit #for test
@page = params[:page] && !params[:page].empty? ? params[:page].to_i : 1
@board = Board.find(params[:id])
@actions = [@board]
@topics = @board.topics.all(:offset => 20*@page-20, :limit => 20, :order => [:displayorder, :id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => params[:page] && !params[:page].empty? ? @topics : @board}
end
end
# POST /boards
# POST /boards.xml
def create
......
......@@ -27,6 +27,7 @@ class UsersController < ApplicationController
# GET /users/new
# GET /users/new.xml
def new
@actions = [:register]
@user = User.new
respond_to do |format|
......@@ -44,12 +45,15 @@ class UsersController < ApplicationController
# POST /users.xml
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
session[:user_id] = @user.id
p session
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
#return render :text => [@user.errors.class, @user.errors]
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
......@@ -83,4 +87,33 @@ class UsersController < ApplicationController
format.xml { head :ok }
end
end
def login
@actions = [:login]
@user = User.new
end
def login_do
@actions = [:login]
@user = User.find_by_name_and_password(params[:user][:name], params[:user][:password])
respond_to do |format|
if @user
session[:user_id] = @user.id
format.html { redirect_to(:root, :notice => 'Login Successfully.') }
format.xml { head :ok }
else
@user = User.new(params[:user])
#@user.errors.add 'incorrect_username_or_password' #TODO: 查API
return render :text => 'incorrect_username_or_password'
format.html { render :action => "login" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
def logout
session[:user_id] = nil
respond_to do |format|
format.html { redirect_to(:back) }
format.xml { head :ok }
end
end
end
module ApplicationHelper
def logged?
@correct_user.id
end
end
\ No newline at end of file
......@@ -3,19 +3,9 @@ class Post < ActiveRecord::Base
belongs_to :user
has_many :comments
def self.today
#now = Time.now
# today = Time.mktime(now.year)
Post.where(['created_at > ?', Date.today ])
end
def self.yesterday
Post.where(['created_at > ? & created_at <? ', Date.today-1, Date.today ])
#Posts.find(:all, :conditions => ["DATE(created_at) = ?", Date.today-1]
Post.where(['created_at < ? and created_at > ?', Date.today, Date.today - 1 ])
end
#Today
#Posts.find(:all, :conditions => ["DATE(created_at) = ?", ]
#Yesterday
#end
end
class User < ActiveRecord::Base
#belongs_to :usergroup
#belongs_to :admingroup
validates_uniqueness_of :name
def to_s
"<a href=\"/space/#{id}\">#{name}</a>".html_safe
end
......
<h1>Editing board</h1>
#encoding: UTF-8
<div id="wrap" class="wrap s_clear">
<div class="main">
<div class="content">
<div id="boardheader" class="s_clear">
<h1 style=""><% @board.name %></h1>
<p class="boardstats">[ <strong><%= @board.topics.size %></strong> 主题 / <%= @board.posts.size %> 帖子]</p>
<div class="boardaction">
<!--<div class="right">
<a href="my.php?item=attention&amp;type=board&amp;action=add&amp;fid=68" id="ajax_attention" class="attention" onclick="ajaxmenu(this);doane(event);">关注</a>
<%= render 'form' %>
<a href="my.php?item=favorites&amp;fid=68" id="ajax_favorite" onclick="ajaxmenu(this);doane(event);">收藏</a>
<a href="rss.php?fid=68&amp;auth=80baas4p%2BS%2FNnT%2BlQanrr%2Blzuk13j9xswULkRK6FhUrlnnrhZxiBsSc%2FwKk" target="_blank" class="feed">RSS</a></div>-->
</div>
<p class="channelinfo"><%= @board.notice %></p><p id="modedby">
版主: *空缺中*</p>
</div>
<%= link_to 'Show', @board %> |
<%= link_to 'Back', boards_path %>
<div class="pages_btns s_clear">
<%= render 'layouts/pages', :count => @board.topics.count %>
<span id="visitedboards" onmouseover="$('visitedboards').id = 'visitedboardstmp';this.id = 'visitedboards';showMenu({'ctrlid':this.id})" class="pageback"><a href="index.php">返回首页</a></span>
<span class="postbtn" id="newspecial" prompt="post_newthread"><%= link_to t('topic.new'), new_topic_path %></span>
<span><%= link_to t('board.control'), edit_board_path(@board) %></span>
</div>
<div id="threadlist" class="threadlist datalist" style="position: relative;">
<form method="post" name="moderate" id="moderate" action="topicadmin.php?action=moderate&amp;fid=68&amp;infloat=yes&amp;nopost=yes">
<input type="hidden" name="formhash" value="eed723b8" />
<input type="hidden" name="listextra" value="page%3D1" />
<table summary="board_68" cellspacing="0" cellpadding="0" class="datatable">
<thead class="colplural">
<tr>
<td colspan="2"></td>
<th>
<ul class="itemfilter s_clear">
</ul>
</th>
<td class="author"><a href="boarddisplay.php?fid=68&amp;filter=&amp;orderby=dateline" class="order "><%= t 'topic.user_name' %>
<%= link_to(t('topic.created_at'), :order => 'creaded_at') %></a></td>
<td class="nums"><a href="boarddisplay.php?fid=68&amp;filter=&amp;orderby=replies" class="order "><%= t 'topic.reply_num' %></a>&nbsp;
<a href="boarddisplay.php?fid=68&amp;filter=&amp;orderby=views" class="order "><%= t 'topic.view_num' %></a></td>
<td class="lastpost"><cite><a href="boarddisplay.php?fid=68&amp;filter=&amp;orderby=lastpost" class="order order_active"><%= t 'topic.post_last' %></a></cite></td>
</tr>
</thead>
<% @topics.each do |topic| %>
<tbody id="normalthread_<%= topic.id %>">
<tr>
<td class="folder">
<%= link_to image_tag(case
when topic.locked
"topic/locked.gif"
when topic.displayorder != 0
"topic/displayorder#{topic.displayorder}.gif"
else
"topic/new.gif"
end), topic, :target => :_blank %>
</td>
<td class="icon">
&nbsp;</td>
<th class="subject common">
<label>&nbsp;</label>
<span id="thread_<%= topic.id %>"><%= topic %></span>
<%= link_to(t('topic.control.delete'), control_topic_path(topic, :deleted => 1)) %>
<%= link_to(t('topic.control.digest'), control_topic_path(topic, :digest => 1)) %>
<%= link_to(t('topic.control.displayorder'), control_topic_path(topic, :displayorder => 1)) %>
<%= link_to(t('topic.control.lock'), control_topic_path(topic, :locked => 1)) %>
<%= link_to(t('topic.control.highlight'), control_topic_path(topic, :highlight => 0xFF0000)) %>
</th>
<td class="author">
<cite>
<%= topic.user %>
</cite>
<em><%=l topic.posts.last.updated_at, :format => :short %></em>
</td>
<td class="nums"><strong><%= topic.posts.size - 1 %></strong></td>
<td class="lastpost">
<cite><%= topic.posts.last.user %></cite>
<em><span title="<%= topic.posts.last.updated_at %>"><%= link_to (l topic.posts.last.updated_at, :format => :short), topic.posts.last %></span></a></em>
</td>
</tr>
</tbody>
<% end %></table>
</form>
</div>
<div class="pages_btns s_clear">
<%= render 'layouts/pages', :count => @board.topics.count %>
<span id="visitedboards" onmouseover="$('visitedboards').id = 'visitedboardstmp';this.id = 'visitedboards';showMenu({'ctrlid':this.id})" class="pageback"><a href="index.php">返回首页</a></span>
<span class="postbtn" id="newspecialtmp" ><%= link_to t('topic.new'), new_topic_path %></span>
</div>
<p id="notice"><%= notice %></p>
<%# fast newtopic %>
<%= form_tag :controller => :topics do %>
<p>
<%=t 'topic.title' %><%= text_field_tag "topic[name]" %>
</p>
<p>
<%= text_area_tag "post[content]" %>
</p>
<%= hidden_field_tag "topic[category_id]", @board.id%>
<%= hidden_field_tag "topic[category_type]", :board%>
<%= submit_tag t("topic.submit") %>
<% end %>
<dl id="onlinelist">
<dt>
<span class="headactions"><a href="boarddisplay.php?fid=68&amp;page=1&amp;showoldetails=yes#online" class="nobdr"><img src="images/default/collapsed_yes.gif" alt="" /></a></span>
<h3>正在浏览此版块的会员</h3>
</dt>
</dl>
</div>
</div>
<ul class="popupmenu_popup postmenu" id="newspecial_menu" style="display: none">
<li><a href="post.php?action=newthread&amp;fid=68" onclick="showWindow('newthread', this.href);doane(event)">发新话题</a></li><li class="poll"><a href="post.php?action=newthread&amp;fid=68&amp;special=1">发布投票</a></li><li class="reward"><a href="post.php?action=newthread&amp;fid=68&amp;special=3">发布悬赏</a></li><li class="debate"><a href="post.php?action=newthread&amp;fid=68&amp;special=5">发布辩论</a></li><li class="activity"><a href="post.php?action=newthread&amp;fid=68&amp;special=4">发布活动</a></li><li class="trade"><a href="post.php?action=newthread&amp;fid=68&amp;special=2">发布商品</a></li></ul>
<ul class="popupmenu_popup headermenu_popup filter_popup" id="filtertype_menu" style="display: none;">
<li><a href="boarddisplay.php?fid=68">全部</a></li>
<li ><a href="boarddisplay.php?fid=68&amp;filter=poll">投票</a></li><li ><a href="boarddisplay.php?fid=68&amp;filter=trade">商品</a></li><li ><a href="boarddisplay.php?fid=68&amp;filter=reward">悬赏</a></li><li ><a href="boarddisplay.php?fid=68&amp;filter=activity">活动</a></li><li ><a href="boarddisplay.php?fid=68&amp;filter=debate">辩论</a></li></ul>
<ul class="popupmenu_popup" id="visitedboards_menu" style="display: none">
<li><a href="boarddisplay.php?fid=2&amp;sid=6e1Kys">综合讨论</a></li><li><a href="boarddisplay.php?fid=23&amp;sid=6e1Kys">版主申请</a></li><li><a href="boarddisplay.php?fid=48&amp;sid=6e1Kys">文文最速新闻</a></li><li><a href="boarddisplay.php?fid=76&amp;sid=6e1Kys">幻想乡大温泉</a></li></ul>
<script type="text/javascript">document.onkeyup = function(e){keyPageScroll(e, 0, 1, 'boarddisplay.php?fid=68', 1);}</script>
<div id="ad_footerbanner1"></div><div id="ad_footerbanner2"></div><div id="ad_footerbanner3"></div>
<script>$('umenu').innerHTML = '<span id="myrepeats" onmouseover="showMenu(this.id)">[切换]</span>' + $('umenu').innerHTML;</script><ul id="myrepeats_menu" class="popupmenu_popup" style="display:none;"><li class="wide" style="clear:both"><a href="plugin.php?id=myrepeats:memcp">设置马甲</a></li></ul></div>
</div><ul class="popupmenu_popup headermenu_popup" id="plugin_menu" style="display: none"> <li><a id="mn_plugin_family_family" href="plugin.php?id=family:family">家族门派</a></li>
</ul>
<ul class="popupmenu_popup headermenu_popup" id="1nNcin_menu" style="display: none"><li><a href="plugin.php?id=moodwall" hidefocus="true" >心情墙壁</a></li><li><a href="plugin.php?id=dps_medalcenter" hidefocus="true" >勋章中心</a></li><li><a href="magic.php" hidefocus="true" >道具中心</a></li><li><a href="plugin.php?id=rs_sign:sign" hidefocus="true" >每日签到</a></li><li><a href="pet.php" hidefocus="true" >口袋东方</a></li><li><a href="plugin.php?id=promotion:promotion" hidefocus="true" >宣传中心</a></li><li><a href="bank.php" hidefocus="true" >社区银行</a></li><li><a href="plugin.php?id=family:family" hidefocus="true" >家族领地</a></li></ul>
\ No newline at end of file
......@@ -2,9 +2,8 @@
<div class="itemtitle s_clear">
<p class="right boardcount">
<%=t 'datetime.today' %>: <em><%= Post.today.count %> </em>,
<%=t 'datetime.yesterday' %>: <em><%= Post.yesterday.count %></em>
<%=t 'datetime.yesterday' %>: <em><%= Post.yesterday.count %></em>,
<%=t 'stat.total' %>: <em><%= Post.count %></em>
</p>
</div><div class="mainbox list">
<span class="headactions">
......
......@@ -22,6 +22,7 @@
<span id="visitedboards" onmouseover="$('visitedboards').id = 'visitedboardstmp';this.id = 'visitedboards';showMenu({'ctrlid':this.id})" class="pageback"><a href="index.php">返回首页</a></span>
<span class="postbtn" id="newspecial" prompt="post_newthread"><%= link_to t('topic.new'), new_topic_path %></span>
<span><%= link_to t('board.control'), edit_board_path(@board) %></span>
</div>
......@@ -100,6 +101,7 @@
<%= render 'layouts/pages', :count => @board.topics.count %>
<span id="visitedboards" onmouseover="$('visitedboards').id = 'visitedboardstmp';this.id = 'visitedboards';showMenu({'ctrlid':this.id})" class="pageback"><a href="index.php">返回首页</a></span>
<span class="postbtn" id="newspecialtmp" ><%= link_to t('topic.new'), new_topic_path %></span>
</div>
<p id="notice"><%= notice %></p>
......
......@@ -8,18 +8,22 @@
<div id="topbar" name="TOP">
<div class="topanel">
<div id="memberp">
<cite><a href="space.php?uid=359" class="noborder">zh99998</a></cite>
<% if logged? %>
<cite><a href="space.php?uid=359" class="noborder"><%= @correct_user %> </a></cite>
<span class="pipe">|</span>
<a href="my.php?item=threads">my</a>
<a href="http://www.touhou.cc/blog/space.php?uid=359" target="_blank">space</a>
<a id="myprompt" href="notice.php" >notice</a>
<%= link_to t('user.my'), @correct_user %>
<%= link_to t('user.space'), @correct_user %>
<%= link_to t('user.notice'), @correct_user %>
<span id="myprompt_check"></span>
<a href="pm.php" id="pm_ntc" target="_blank">pm</a>
<%= link_to t('user.pm'), @correct_user %>
<span class="pipe">|</span>
<a href="memcp.php">memcp</a>
<a href="logging.php?action=logout&amp;formhash=eed723b8">logout</a>
<%= link_to t('user.logout'), logout_path %>
<% else %>
<%= link_to t('user.login'), login_path %>
<%= link_to t('user.register'), new_user_path %>
<% end %>
</div>
<form method="post" id="searchform" action="search.php">
......
<%= form_for(@user, :url => :login ) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label t('user.name') %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label t('user.password') %><br />
<%= f.text_field :password %>
</div>
<div class="actions">
<%= f.submit t('user.login') %>
</div>
<% end %>
<h1>New user</h1>
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<%= render 'form' %>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= link_to 'Back', users_path %>
<div class="field">
<%= f.label t('user.name') %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label t('user.password') %><br />
<%= f.text_field :password %>
</div>
<div class="field">
<%= f.label t('user.password_repeat') %><br />
<%= f.text_field :password %>
</div>
<div class="field">
<%= f.label t('user.email') %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit t('user.register') %>
</div>
<% end %>
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<b><%=t 'user.name' %>:</b>
<%= @user.name %>
</p>
<p>
<b>Password:</b>
<b><%=t 'user.password' %>:</b>
<%= @user.password %>
</p>
<p>
<b>Email:</b>
<b><%=t 'user.email' %>:</b>
<%= @user.email %>
</p>
<p>
<b>Credit:</b>
<b><%=t 'user.credit' %>:</b>
<%= @user.credit %>
</p>
<p>
<b>Usergroup:</b>
<%= @user.usergroup %>
</p>
<p>
<b>Admingroup:</b>
<%= @user.admingroup %>
</p>
<%= link_to 'Edit', edit_user_path(@user) %> |
......
......@@ -2,9 +2,24 @@
# by tsechingho (http://github.com/tsechingho)
zh-CN:
user:
login: "登陆"
register: "注册"
logout: "退出"
my: "我的中心"
space: "空间"
notice: "提醒"
pm: "短消息"
name: "用户名"
password: "密码"
password_repeat: "重复密码"
email: "邮箱"
forum:
next: "下一页"
prev: "上一页"
board:
control: "管理面板"
stat:
onlineuser: "在线人数"
total: "总计"
......
......@@ -6,23 +6,28 @@ Reliz::Application.routes.draw do
root :to => 'boards#index'
resources :users
get 'login' => 'users#login'
post 'login' => 'users#login_do'
get 'logout' => 'users#logout'
get 'register' => 'users#new'
resources :blocks
resources :boards
match 'forum' => 'boards#index'
match 'forum/:id/edit' => 'boards#edit', :id => /\d+/
match 'forum/:id/(/:page)' => 'boards#show', :id => /\d+/, :page => /\d+/
resources :posts
match 'forum/:topic_id/new' => 'posts#new', :topic_id => /\d+/ #����ظ�
match 'topic/:topic_id/new' => 'posts#new', :topic_id => /\d+/ #����ظ�
resources :topics
match 'topic/:id/(/:page)' => 'topics#show', :id => /\d+/, :page => /\d+/
match 'forum/:forum_id/new' => 'topics#new', :forum_id => /\d+/ #
get 'topic/control' => 'topics#control'
match ':something/:anything', :controller => 'application', :action => 'redirect_to_thc', :something => /forum|boards|topic|topics|posts/, :anything => /.*/
match '/:anything', :controller => 'application', :action => 'redirect_to_thc', :anything => /.*/
match '(:something)/:anything/', :controller => 'application', :action => 'redirect_to_thc', :something => /forum|boards|topic|topics|posts/, :anything => /.*/
......
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
t.string :nickname
t.string :password
t.string :email
t.references :usergroup
t.references :admingroup
t.string :regip
t.string :lastloginip
t.integer :readnum
t.integer :viewnum
t.integer :onlinetime
t.integer :credit
t.integer :credit1
t.integer :credit2
t.integer :credit3
t.integer :credit4
t.integer :credit5
t.integer :credit6
t.integer :credit7
t.integer :credit8
t.timestamps
end
end
def self.down
drop_table :users
end
end
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name, :null => false
t.string :nickname, :default => '', :null => false
t.string :password, :null => false
t.string :email, :default => '', :null => false
t.references :usergroup, :default => '', :null => false
t.references :admingroup, :default => '', :null => false
t.string :regip, :default => '', :null => false
t.string :lastloginip, :default => '', :null => false
t.integer :readnum, :default => 0, :null => false
t.integer :viewnum, :default => 0, :null => false
t.integer :onlinetime, :default => 0, :null => false
t.integer :credit, :default => 0, :null => false
t.integer :credit1, :default => 0, :null => false
t.integer :credit2, :default => 0, :null => false
t.integer :credit3, :default => 0, :null => false
t.integer :credit4, :default => 0, :null => false
t.integer :credit5, :default => 0, :null => false
t.integer :credit6, :default => 0, :null => false
t.integer :credit7, :default => 0, :null => false
t.integer :credit8, :default => 0, :null => false
t.timestamps
end
end
def self.down
drop_table :users
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20101226125042) do
ActiveRecord::Schema.define(:version => 20111036031158) do
create_table "boards", :force => true do |t|
t.string "name"
......@@ -79,9 +79,10 @@ ActiveRecord::Schema.define(:version => 20101226125042) do
t.integer "user_id", :null => false
t.integer "type_id"
t.integer "category_id", :null => false
t.string "category_type", :default => "", :null => false
t.string "name", :default => "", :null => false
t.string "category_type", :null => false
t.string "name", :null => false
t.integer "displayorder", :default => 0, :null => false
t.integer "highlight", :default => 0, :null => false
t.integer "views", :default => 0, :null => false
t.integer "readperm", :default => 1, :null => false
t.boolean "locked", :default => false, :null => false
......@@ -93,26 +94,26 @@ ActiveRecord::Schema.define(:version => 20101226125042) do
end
create_table "users", :force => true do |t|
t.string "name"
t.string "nickname"
t.string "password"
t.string "email"
t.integer "usergroup_id"
t.integer "admingroup_id"
t.string "regip"
t.string "lastloginip"
t.integer "readnum"
t.integer "viewnum"
t.integer "onlinetime"
t.integer "credit"
t.integer "credit1"
t.integer "credit2"
t.integer "credit3"
t.integer "credit4"
t.integer "credit5"
t.integer "credit6"
t.integer "credit7"
t.integer "credit8"
t.string "name", :null => false
t.string "nickname", :default => "", :null => false
t.string "password", :null => false
t.string "email", :default => "", :null => false
t.integer "usergroup_id", :default => 0, :null => false
t.integer "admingroup_id", :default => 0, :null => false
t.string "regip", :default => "", :null => false
t.string "lastloginip", :default => "", :null => false
t.integer "readnum", :default => 0, :null => false
t.integer "viewnum", :default => 0, :null => false
t.integer "onlinetime", :default => 0, :null => false
t.integer "credit", :default => 0, :null => false
t.integer "credit1", :default => 0, :null => false
t.integer "credit2", :default => 0, :null => false
t.integer "credit3", :default => 0, :null => false
t.integer "credit4", :default => 0, :null => false
t.integer "credit5", :default => 0, :null => false
t.integer "credit6", :default => 0, :null => false
t.integer "credit7", :default => 0, :null => false
t.integer "credit8", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
......
This diff is collapsed.
7580
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment