Menu

[r545]: / wikipp / trunk / data.cpp  Maximize  Restore  History

Download this file

132 lines (119 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Nothing meanwhile */
#include "cxxmarkdown/markdowncxx.h"
#include "wiki.h"
namespace data {
login_form::login_form(wiki *_w) :
w(_w),
username("username",w->gettext("Username")),
password("password",w->gettext("Password")),
login("login",w->gettext("Login"))
{
*this & username & password & login;
username.set_nonempty();
password.set_nonempty();
}
bool login_form::validate()
{
if(!form::validate())
return false;
if(w->users.check_login(username.get(),password.get()))
return true;
password.not_valid();
return false;
}
string master::markdown(string s)
{
string tmp;
markdown2html(s,tmp);
return tmp;
}
page_form::page_form(wiki *_w):
w(_w),
title("title",w->gettext("Title")),
content("content",w->gettext("Content")),
sidebar("sidebar",w->gettext("Sidebar")),
save("save",w->gettext("Save")),
save_cont("save_cont",w->gettext("Save and Continue")),
preview("preview",w->gettext("Preview")),
users_only("users_only")
{
*this & title & content & sidebar & save & save_cont & preview & users_only;
fields<<title<<content<<sidebar;
buttons<<save<<save_cont<<preview<<users_only;
users_only.help=w->gettext("Disable editing by visitors");
users_only.error_msg=w->gettext("Please Login");
title.set_nonempty();
content.set_nonempty();
content.rows=25;
content.cols=60;
sidebar.rows=10;
sidebar.cols=60;
}
bool page_form::validate()
{
bool res=form::validate();
if(users_only.get() && !w->users.auth()) {
users_only.not_valid();
users_only.set(false);
return false;
}
return res;
}
options_form::options_form(wiki *_w):
w(_w),
users_only("uonly",w->gettext("Users Only")),
contact_mail("contact",w->gettext("Contact e-mail")),
wiki_title("wtitle",w->gettext("Wiki Title")),
about("about",w->gettext("About Wiki")),
copyright("copy",w->gettext("Copyright String")),
submit("submit",w->gettext("Submit"))
{
*this & users_only & contact_mail & wiki_title & copyright & about & submit;
wiki_title.set_nonempty();
copyright.set_nonempty();
contact_mail.set_nonempty();
about.set_nonempty();
about.rows=10;
about.cols=40;
users_only.help=w->gettext("Disable creation of new articles by visitors");
}
new_user_form::new_user_form(wiki *_w):
w(_w),
username("username",w->gettext("Username")),
password1("p1",w->gettext("Password")),
password2("p2",w->gettext("Confirm")),
submit("submit",w->gettext("Submit"))
{
*this & username & password1 & password2 ;
username.set_nonempty();
password1.set_nonempty();
password2.set_equal(password1);
vector<string> const &quiz=w->app.config.slist("wikipp.quiz_q");
int i=1;
for(vector<string>::const_iterator p=quiz.begin(),e=quiz.end();p!=e;++p) {
this->quiz.push_back(widgets::checkbox((boost::format("%d") % i).str()));
this->quiz.back().help=*p;
*this & this->quiz.back();
i++;
}
*this & submit;
}
bool new_user_form::validate()
{
if(!form::validate())
return false;
vector<long> const &quiz=w->app.config.llist("wikipp.quiz_a");
list<widgets::checkbox>::iterator qp=this->quiz.begin();
for(vector<long>::const_iterator p=quiz.begin(),e=quiz.end();p!=e;++p) {
if(qp==this->quiz.end() || qp->get()!=*p)
return false;
++qp;
}
if(w->users.user_exists(username.get())) {
username.error_msg=w->gettext("This user exists");
username.not_valid();
return false;
}
return true;
}
} // namespac data
MongoDB Logo MongoDB