示例#1
0
def signUp():
    if request.method == 'POST':
        # getting and sanatizing email
        email = request.form.get("email")
        email = sec.sanitize(
            email,
            characters=
            'abcdefghijklomnopqrstuvwxyzABCDEFGHIJKLMNOPQRTUVWXYZ1234567890@.')

        # checking if account with email already exists
        Base = declarative_base()
        engine = create_engine('sqlite:///mainDatabase.db',
                               poolclass=SingletonThreadPool)
        Base.metadata.bind = engine
        DBSession = sessionmaker(bind=engine)
        s = DBSession()
        try:
            s.query(database.Account).filter(
                database.Account.email == email).one()
            accountAlreadyExists = True
        except:
            accountAlreadyExists = False

        if not accountAlreadyExists:
            # getting form variables, generating salt, and sanatizing the retreived variables
            password = request.form.get("password")
            name = request.form.get("name")
            group = request.form.get("group")
            print(name, group)
            name = sec.sanitize(name)
            group = sec.sanitize(group)
            print(name, group)

            salt = str(random.randint(10000, 99999))

            # hashing password with salt
            hashed_password = hashlib.sha512(
                password.encode('utf-8') + salt.encode('utf-8')).hexdigest()

            # uploading account to database
            new_person = database.Account(name=name,
                                          password=hashed_password,
                                          salt=int(salt),
                                          email=email,
                                          group=group)
            s.add(new_person)
            s.commit()

            # updating session variables and logging in
            session['admin'] = False
            session['name'] = name
            session['group'] = group
            session['logged_in'] = True

            # redirecting to home
            return jsonify('home')
        elif accountAlreadyExists:
            # if account already exists redirecting to login page
            return jsonify('login')
示例#2
0
 def test_pop_client(self):
     account_config = {
         "user_name": "foo@localhost",
         "password": "******",
         "protocol": "pop3",
         "hostname": "localhost:{0}".format(SpamCanPOPTest.server_port),
         "smtp_host": "localhost"
     }
     account = database.Account(account_config)
     mail_handler = MailUtil()
     protocol_handler = mail_handler.request(account)
     count = protocol_handler.get_stats()
     protocol_handler.disconnect()
     self.assert_(count == 1)
示例#3
0
def add_account():
    error = ""
    account_config = {}
    account_config["user_name"] = request.forms.get('user_name')
    account_config["password"] = request.forms.get('password')
    account_config["hostname"] = request.forms.get('hostname')
    account_config["protocol"] = request.forms.get('protocol')
    account_config["smtp_host"] = request.forms.get('smtp_host')
    account = database.Account(account_config)
    try:
        protocol_handler = mail_handler.request(account)
        protocol_handler.disconnect()
    except Exception as e:
        error = "Connection error ({0})".format(e)
    else:
        db.add_account(account_config)
    accounts = db.fetch_all()
    redirect("/?error={0}".format(error))
示例#4
0
async def syncdiscord(bot, thing: extradiscord.discord.Message, arguments):
    """Crea un nuovo account usando il tuo ID di Discord.
    
Sintassi: `{symbol}syncdiscord`"""
    # Set status to typing
    await status_typing(bot, thing)
    # Check the command syntax
    if len(arguments) != 0:
        await display_help(bot, thing, syncdiscord)
        return
    # Open a new database session
    session = database.Session()
    # Check if the user already exists
    user = session.query(database.Account).filter_by(id=thing.author.id).first()
    if user is not None:
        await answer(bot, thing, "⚠ L'account è già stato registrato.")
        return
    # Create a new user
    user = database.Account(id=thing.author.id)
    session.add(user)
    session.commit()
    # Notify the sender
    await answer(bot, thing, "✅ Account registrato con successo!")