Skip to content
Browse files

remove database code.

  • Loading branch information...
1 parent f0d521a commit e079548c41f90e61152c941d98021a81c287a877 @winbomb committed
Showing with 2 additions and 84 deletions.
  1. +1 −1 Makefile
  2. +0 −43 src/login.opa
  3. +1 −40 src/main.opa
View
2 Makefile
@@ -11,7 +11,7 @@ SRC_FILES=$(wildcard $(SRC_DIR)/*.opa)
BIN_DIR=bin
EXEC_NAME=./mahjong.exe
-RUN_OPTS= --verbose 2 --db-remote:mahjong localhost:27017
+RUN_OPTS=
DEBUG_NAME=./mahjong.exe --verbose 8
EXEC=$(BIN_DIR)/$(EXEC_NAME)
View
43 src/login.opa
@@ -38,32 +38,6 @@ type Player.status = {online}
type Login.user = {unlogged} or {Player.t user};
-type Access.t = {
- string id,
- string name,
- string time,
- string ip,
- string lang,
- string agent,
- string render
-}
-
-database mahjong {
- int /view_count //访问次数
- int /login_count //登录次数
- int /game_count //游戏次数
- list(Access.t) /access_list //访问列表
-}
-
-exposed function record_access(access_info){
- /mahjong/login_count++
- /mahjong/access_list <+ {access_info with time: Date.to_string(Date.now())}
-}
-
-exposed function increase_view(){
- /mahjong/view_count++
-}
-
module Login {
state = UserContext.make({unlogged})
@@ -115,22 +89,6 @@ module Login {
user = {~name, idx: -1, status: {online}, coins: DEFAULT_COINS};
set_cookie("login_name",name);
- req = Option.get(HttpRequest.get_request());
- ip = IPv4.string_of_ip(HttpRequest.Generic.get_ip(req))
- lang = ServerI18n.request_lang(req)
- user_compat = HttpRequest.Generic.get_user_agent(req)
-
- access_info = {
- id: Random.string(8),
- name: name,
- time: "",
- ip: ip,
- lang: lang,
- agent: get_agent(user_compat),
- render: get_render(user_compat)
- }
- record_access(access_info);
-
UserContext.change(function(_){{user:user}},state);
Client.goto("/hall");
}
@@ -141,7 +99,6 @@ module Login {
if(not(String.is_empty(login_name))){
Dom.set_value(#username,login_name);
}
- increase_view();
}
function login_view(){
View
41 src/main.opa
@@ -75,8 +75,7 @@ function start(url){
case {path:["login"] ... } : Login.login_view()
case {path:["game",x|_] ...} : game_view(x);
case {path:["how_to_play.html"] ...}: @static_resource("resources/how_to_play.html");
- case {path:["admin"] ...} : Main.admin_page()
- case {path:["hall"] ...} : login_required(function(){Page.game_list_view()})
+ case {path:["hall"] ...} : login_required(function(){Page.game_list_view()})
case {path: _ ...} : Main.fourOffour()
}
@@ -96,42 +95,4 @@ module Main {
<><h1>404</h1></>
);
}
-
- //这种处理方式似乎不好,应该在查询的时候只查询出需要的结果
- exposed function get_access_list(){
- access_list = /mahjong/access_list
- len = List.length(access_list);
- result = if(len > 200) List.drop(len-200,access_list) else access_list;
- List.rev(result);
- }
-
- function admin_page(){
- Resource.page("login list",
- <h2>访问次数:{/mahjong/view_count}</h2>
- <h2>登录次数:{/mahjong/login_count}</h2>
- <h2>访问列表:</h2>
- <table border="1px">
- <tr>
- <th>用户ID</th>
- <th>用户名</th>
- <th>登录时间</th>
- <th>IP</th>
- <th>LANG</th>
- <th>AGENT</th>
- <th>Render</th>
- </tr>
- {List.map(function(access){
- <tr>
- <td width="100px"> {access.id} </td>
- <td width="150px"> {access.name}</td>
- <td width="200px"> {access.time}</td>
- <td width="200px"> {access.ip}</td>
- <td width="100px"> {access.lang}</td>
- <td width="100px"> {access.agent}</td>
- <td width="100px"> {access.render}</td>
- </tr>
- },get_access_list())}
- </table>
- );
- }
}

0 comments on commit e079548

Please sign in to comment.
Something went wrong with that request. Please try again.