The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
user_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Thomas Baumhauer <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "user_handler.hpp"
16 #include "config.hpp"
18 
19 #include <ctime>
20 
22  const std::string& /*subject*/, const std::string& /*message*/) {
23 
24  //If this user is registered at all
25  if(!user_exists(to_user)) {
26  throw error("Could not send email. No user with the name '" + to_user + "' exists.");
27  }
28 
29  // If this user did not provide an email
30  if(get_mail(to_user) == "") {
31  throw error("Could not send email. The email address of the user '" + to_user + "' is empty.");
32  }
33 
34  throw user_handler::error("This server is configured not to send email.");
35 }
36 
38 }
39 
41  srand(static_cast<unsigned>(time(nullptr)));
42 
43  std::stringstream ss;
44 
45  for(int i = 0; i < length; i++) {
46  ss << (rand() % 10);
47  }
48 
49  return ss.str();
50 }
virtual std::string get_mail(const std::string &user)=0
Used in send_mail().
static l_noret error(LoadState *S, const char *why)
Definition: lundump.cpp:29
bool send_mail(const std::string &to_user, const std::string &subject, const std::string &message)
Sends an email to the specified address.
Definitions for the interface to Wesnoth Markup Language (WML).
GLuint GLsizei GLsizei * length
Definition: glew.h:1793
void init_mailer(const config &c)
Initiate the mailer object.
virtual bool user_exists(const std::string &name)=0
Returns true if a user with the given name exists.
std::string create_salt(int length=8)
Create a random string of digits for password encryption.
size_t i
Definition: function.cpp:1057
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503