Ejemplo n.º 1
0
int main(){
    char ch[NUM]={0};
    printf("请输入email的地址:\n");
    int count=getString(ch,NUM-1);
    int ret=validEmail(ch);
    if (ret==1) {
        printf("%s是合法的email地址\n",ch);
    }
    if (count==NUM-1) {
        clearBuffer();
    }
    getString(ch,NUM-1);
    return 0;
}
Ejemplo n.º 2
0
void frmCreateUser::checkCreateEnable()
{
	bool e = true;
	e &= !ui.leLogin->text().isEmpty();
	e &= !ui.lePass->text().isEmpty();
	e &= !ui.leRepeatPass->text().isEmpty();
	e &= !ui.leMail->text().isEmpty();
	e &= validEmail(ui.leMail->text());
	e &= (ui.lePass->text().length() >= 5);
	e &= (ui.lePass->text() == ui.leRepeatPass->text());
	ui.pbCreate->setEnabled(e);

	if (!ui.lePass->text().isEmpty() && (ui.lePass->text().length() < 5))
		ui.lbStatus->setText(tr("Hasło musi mieć conajmniej 5 znaków!"));
	else if(ui.lePass->text() != ui.leRepeatPass->text())
		ui.lbStatus->setText(tr("Wpisane hasła różnią się od siebie!"));
	else if(!ui.leMail->text().isEmpty() && !validEmail(ui.leMail->text()))
		ui.lbStatus->setText(tr("Wpisz poprawny adres e-mail."));
	else 
		ui.lbStatus->setText(tr("Wpisz dane potrzebne do założenia konta"));
	if(e)
		ui.lbStatus->setText(tr("Teraz możesz założyć konto na serwerze NAPI-PROJEKT"));
}
Ejemplo n.º 3
0
void Pages::registration(Document *doc){

    if(path != "/register")
        return;

    std::string name = cgi("name"), email = cgi("email"), pw = cgi("pw");

    if(Session::user())
        doc->redirect("/");

    else if(cgi.getEnvironment().getRequestMethod() != "POST")
        form(doc);

    else if(name.empty())
        form(doc, "Please specify a display name.");

    else if(email.empty())
        form(doc, "Please specify an email address.");
    else if(!validEmail(email))
        form(doc, "Invalid email address.");

    else if(pw.empty())
        form(doc, "Please specify a password.");
    else if(pw != cgi("pwconf"))
        form(doc, "Passwords mismatch.");

    else{

        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE lower(name) = lower($1) OR lower(email) = lower($2))", name, email)[0][0] == "t")
            return form(doc, "Sorry, name or email already in use.");

        DB::Result r = DB::query(
            "INSERT INTO users (name, password, email, registration, last_login) "
            "VALUES ($1, crypt($2, gen_salt('bf')), $3, 'now', 'now') "
            "RETURNING id", name, pw, email);

        if(r.empty())
            return form(doc, "Erm, something went wrong. Please try again.");

        User u = User(number(r[0][0]), name);
        log("New user: "******" (" + number(u.id) + ")");
        doc->addHttp("Set-Cookie: sid=" + Session::login(u) + ";Max-Age=2592000\n"); // 30 days
        doc->redirect(u.url() + "?welcome=1");

    }

}
Ejemplo n.º 4
0
void Pages::account(Document *doc){

    if(path == "/account/delete")
        return deleteAccount(doc);
    else if (path == "/goodbye")
        return doc->setHtml("html/goodbye.tpl", "Goodbye");

    if(path != "/account")
        return;

    if(!Session::user())
        return doc->redirect("/login?redirect=/account");

    Account a(Session::user().id);

    if(cgi.getEnvironment().getRequestMethod() != "POST" || Session::nonce() != cgi("nonce"))
        return form(doc, a);

    Session::newNonce();

    std::string name = cgi("name");
    if(!name.empty() && name != a.name){
        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE lower(name) = lower($1))", name)[0][0] == "t")
            return form(doc, a, "Name already in use.");
    }
    else
        name = a.name;

    std::string email = cgi("email");
    if(!email.empty() && email != a.email){
        if(!validEmail(email))
            return form(doc, a, "Invalid email address.");
        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE lower(email) = lower($1))", email)[0][0] == "t")
            return form(doc, a, "Email already in use.");
    }
    else
        email = a.email;

    std::string oldpw = cgi("oldpw"), newpw = cgi("newpw");
    if(!oldpw.empty() && !newpw.empty()){
        if(newpw != cgi("newpwconf"))
            return form(doc, a, "Passwords mismatch.");
        if(DB::query("SELECT EXISTS (SELECT 1 FROM users WHERE id = " + number(a.id) + " AND password = crypt($1, password))", oldpw)[0][0] != "t")
            return form(doc, a, "Wrong password.");

        // Everything has been checked. Committing.

        DB::query("UPDATE users SET password = crypt($1, gen_salt('bf')) WHERE id = " + number(a.id), newpw);
    }


    DB::query(
        "UPDATE users SET name = $1, email = $2, about = $3, notify = $4 WHERE id = " + number(a.id),
        name, email, cgi("about"), cgi("notify").empty() ? "f" : "t"
    );

    if(a.name != cgi("name")){ // The name has changed.
        log("Renaming user: "******" -> " + cgi("name"));
        Session::destroy();
        Session::start();
        //std::vector<Track> tracks = a.tracks(true);
        //for(std::vector<Track>::iterator i=tracks.begin(); i!=tracks.end(); i++)
            //Media(*i).updateTags();
    }

    doc->setHtml("html/account.tpl", "Your account");
    doc->dict()->SetValueAndShowSection("MESSAGE", "Changes applied.", "MESSAGE");
    Account(a.id).fill(doc->dict());

}