-module (register).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
-define(USER_DOC , {[
{<<"_id">>,<<"null">>},
{<<"_rev">>,<<"null">>},
{<<"nick">>,<<"null">>},
{<<"realname">>,<<"null">>},
{<<"email">>,<<"null">>},
{<<"sex">>,<<"null">>},
{<<"avatar">>,<<"null">>},
{<<"lbsinfo">>,<<"null">>},
{<<"contract">>,<<"null">>},
{<<"intro">>,<<"null">>},
{<<"liketags">>,<<"null">>},
{<<"friends">>,<<"null">>},
{<<"likeuid">>,<<"null">>},
{<<"belikeduid">>,<<"null">>},
{<<"score">>,<<"null">>},
{<<"group">>,<<"null">>},
{<<"private">>,<<"null">>},
{<<"registerdate">>,<<"null">>},
{<<"registerip">>,<<"null">>},
{<<"lastlogin">>,<<"null">>},
{<<"table">>,<<"user">>}
]}).
main()->
Ip = get_client_ip(),
Email = wf:q("email"),
Password = wf:q("password"),
Nickname = wf:q("nickname"),
Server = couchbeam:server_connection("localhost", 5984, "", []),
{ok, Db} = couchbeam:open_db(Server, "image_cache", []),
NewSession = {Email,Password,Nickname},
io:format("New user is ~p~n",[NewSession]),
case NewSession of
{undefined,undefined,undefined}
-> #template { file="./site/templates/register.html",bindings=[{'Ecode',"0"}] };
_ ->
case couchbeam_view:first(Db,{"user","email"},[{key,list_to_binary(Email)}]) of
{ok,_} ->
io:format("this is a new user~n"),
#template { file="./site/templates/register.html",bindings=[{'Ecode',"1"}] };
_ ->
io:format("can be register~n"),
X1 = couchbeam_doc:set_value(<<"email">>,list_to_binary(Email),?USER_DOC),
X2 = couchbeam_doc:set_value(<<"nick">>,list_to_binary(Nickname),X1),
X3 = couchbeam_doc:set_value(<<"password">>,list_to_binary(Password),X2),
X4 = couchbeam_doc:set_value(<<"registerip">>,list_to_binary(Ip),X3),
X5 = couchbeam_doc:delete_value(<<"_id">>,X4),
X6 = couchbeam_doc:delete_value(<<"_rev">>,X5),
case couchbeam:save_doc(Db,X6) of
{ok,SaveSuccess} ->
io:format("User Doc is ~p~n",[SaveSuccess]),
wf:session("userinfo",{
couchbeam_doc:get_value(<<"_id">>,SaveSuccess),
binary_to_list(couchbeam_doc:get_value(<<"email">>,SaveSuccess)),
couchbeam_doc:get_value(<<"nick">>,SaveSuccess),
couchbeam_doc:get_value(<<"space">>,SaveSuccess),
couchbeam_doc:get_value(<<"avatar">>,SaveSuccess)
}),
wf:cookie("Userid", binary_to_list(couchbeam_doc:get_value(<<"_id">>,SaveSuccess)),"/",525600),
wf:redirect("/baiduimage");
_->
#template { file="./site/templates/register.html",bindings=[{'Ecode',"3"}] }
end
end
end.
get_client_ip()->
Request = wf_context:request_bridge(),
Headers = Request:headers(),
IPAddress = lists:keyfind(x_real_ip,1,Headers),
case IPAddress of
{x_real_ip,IP} -> IP;
_ -> "0.0.0.0"
end.
errorCode(T) ->
case T of
"1" -> Out = "Email已经被注册了";
"0" -> Out = "";
"3"->Out = "注册失败";
_ ->Out = ""
end,
Out.
check_login(Email,Password,[])-> "";
check_login(Email,Password,[H|T]) ->
{[_,_,{_,{[{_,CId},_,{_,CEmail},{_,CPassword},_,{_,CNick},{_,CSpace},{_,CAvatar},_]}}]} = H,
M = check_login_2(Email,Password,CEmail,CPassword),
if M == "true" -> {"true",CId,CNick,CSpace,CAvatar};
true -> check_login(Email,Password,T)
end.
check_login_2(Email,Password,CEmail,CPassword) ->
New = {Email,Password},
List_Email = binary_to_list(CEmail),
List_Password = binary_to_list(CPassword),
Old = {binary_to_list(CEmail),binary_to_list(CPassword)},
Empty = {"",""},
case New of Old -> "true";
Empty -> "0";
True -> "1"
end.
分享到:
相关推荐
erlang的Web开发 随着Erlang和FP的普及,总有人想把Erlang用在Web开发上。 虽然这不一定是个靠谱的想法,但是,...Nitrogen 就是其中一个实现。它主要关注在快速开发交互密集型的Web,喜欢Erlang的童鞋可以看一下。
《Nitrogen6X_Hardware_Manual_rev1.3.pdf》是一份详细的硬件手册,其修订版本为第1.3版。该手册是关于Boundary Devices公司发布的i.MX6x Nitrogen6X开发板的技术文档。此开发板是一个基于i.MX6四核应用处理器的低...
注册表注册表服务为 Nitrogen 中的安全主体(设备、应用程序和用户)提供身份和发现服务。安装git clone https://github.com/nitrogenjs/registry cd frontdoor npm install node server.js如何贡献反馈:我们很乐意...
在中国南方亚热带季风森林中,氮素淋溶对增加的氮输入的响应是一个重要的生态研究领域,涉及复杂的氮循环过程及其对环境的影响。本文基于标题、描述、标签及部分内容,深入探讨了这一主题下的关键知识点。...
"nitrogen 聊天室"是一个基于Nitrogen框架构建的内部通信工具,主要用于提升团队间的沟通效率。这个聊天室不仅支持基本的文本信息交流,还具备发送文件和图片的功能,使得工作中的信息传递更为便捷。 Nitrogen是一...
Introduction to Nitrogen
最优水分条件下冬小麦根系吸水、吸氮与根氮含量之间的关系,石建初,左强,在土壤-植物系统中,根系吸收土壤中的水、氮对植物生长以及对土壤中的水、氮运移都具有非常重要的作用。在考虑植物根长的基础之
nitrogen_core的动作系统使得代码组织清晰,易于维护,同时也增强了可测试性。 3. **处理器(Handlers)**:处理器是框架中处理事件和动作的逻辑部分。当用户触发某个事件(如点击、提交表单等)时,处理器会被调用...
标题:“A Versatile, Ultralight, Nitrogen‐Doped Graphene Framework.pdf” 描述的是一篇关于氮掺杂的石墨烯框架(Nitrogen-Doped Graphene Framework, GF)的研究论文,该框架具有多功能、超轻以及氮掺杂的特点...
nitrogen-1.1-wm5.cab WINCE PPC
根据提供的文件信息,以下是对混合量子系统中纠缠复制过程的知识点的详细阐述: 1. 混合量子系统的构成 混合量子系统是由超导传输线腔链和氮空穴色心(NV色心)系综组合而成的。超导传输线腔(resonators)是超导...
Microstructure thermostability of high nitrogen austenitic stainless steel,袁志钟,戴起勋,High nitrogen austenitic stainless steel, Fe24Mn18Cr3Ni0.62N, was isothermal annealed from 750℃ to 900 ℃ ...
Amelioration of nitrogen difference method in legume intercropping,余常兵,李隆,Nitrogen difference method is commonly used to appraise biological nitrogen fixation, which is a well established ...
开源软件,如nITROGEN,意味着其源代码对公众开放,允许用户查看、修改和分发代码。这种开放性促进了技术创新,因为全球的开发者可以协作改进软件,发现并修复潜在的漏洞,同时提供了透明度和信任。对于物联网这样的...
铁膜磁性氮调制,W. H. Zhong,B. K. Tay,The structure and magnetic properties can be modulated by adding nitrogen because of the aleration of Fe atomic valence upon reaction.
CVN impact properties of high-nitrogen austenitic stainless steels,袁志钟,戴起勋,The Charpy v notch (CVN) impact properties of two kinds of high-nitrogen austenitic stainless steels (HNASS) Fe24Mn...
在实际应用中,`nitrogen-css`的文档通常会包含详细的API参考、示例代码和最佳实践,帮助开发者快速上手。在提供的`nitrogen-css-main`压缩包文件中,我们可以找到框架的核心文件,包括CSS样式表、JavaScript库...
具有一般内坐标的 Rovibronic 能量的数值和迭代技术
Nitrogen fixation of faba bean interacting with a non-legume in two contrasting intercropping systems,范分良,余常兵,A field experiment was carried out to quantify biological nitrogen fixation (BNF)...