def test_user_insert(self): properties = { 'current.dir': os.path.abspath(os.getcwd()), 'package.dir': os.path.dirname(snapsnare.__file__), 'home.dir': str(Path.home()), 'app.name': 'snapsnare' } ds = utils.load_json(properties, 'snapsnare-ds.json') connector = ConnectorFactory.create_connector(ds) connector.connect() user_repository = UserRepository(connector) user = { 'username': '******', 'password': '******' } id_ = user_repository.insert(user) self.assertIsNotNone(id_, 'no id') user = user_repository.find_by(id=id_) connector.rollback() connector.close() self.assertIsNotNone(user, 'no user') username = user.get('username') self.assertIsNotNone(username, 'no username') expected = '*****@*****.**' self.assertEqual(expected, username, 'invalid state, expected {} got {}'.format(expected, username))
def show(): connector = current_app.connector if request.method == 'GET': section_repository = SectionRepository(connector) sections = section_repository.list_by(active=1, order_by='id') connector.close() return render_template('password_forgotten/password_forgotten.html', sections=sections) if request.method == 'POST': username = request.form['username'] user_repository = UserRepository(connector) user = user_repository.find_by(username=username, active=1) if not user: flash('Invalid account state', 'danger') return redirect(url_for('login.show')) # disable previous resets of this user. reset = {"active": 0} reset_repository = ResetRepository(connector) reset_repository.update(reset, where={"username": user["username"]}) # create an active reset for this user. reset = { "active": 1, "uuid": str(uuid4()), "username": user["username"], } reset_repository.insert(reset) properties = current_app.properties settings = utils.load_json(properties, 'snapsnare.json') credentials = settings['gmail'] snapsnare = settings['snapsnare'] host = snapsnare['host'] template_repository = TemplateRepository(connector) template = template_repository.find_by(template='reset') content = template['content'] content = content.replace("{host}", host) content = content.replace("{uuid}", reset['uuid']) connector.commit() gmail.send_email(credentials, reset['username'], "Reset your account on snapsnare.org", content) flash( 'A reset request is successfully created. Please check your e-mail to reset your password.', 'success') return redirect(url_for('login.show'))
def __init__(self): logging.Handler.__init__(self) properties = { 'current.dir': os.path.abspath(os.getcwd()), 'package.dir': os.path.dirname(snapsnare.__file__), 'home.dir': str(Path.home()), 'app.name': 'snapsnare' } ds = utils.load_json(properties, 'snapsnare-ds.json') self.__connector = ConnectorFactory.create_connector(ds)
def test_activity_list(self): properties = { 'current.dir': os.path.abspath(os.getcwd()), 'package.dir': os.path.dirname(snapsnare.__file__), 'home.dir': str(Path.home()), 'app.name': 'snapsnare' } ds = utils.load_json(properties, 'snapsnare-ds.json') connector = ConnectorFactory.create_connector(ds) connector.connect() activity_repository = ActivityRepository(connector) activities = activity_repository.list() connector.close()
from snapsnare.templates.snaps.snaps import snaps from snapsnare.templates.login.login import login from snapsnare.templates.login.user import User from snapsnare.templates.password_forgotten.password_forgotten import password_forgotten application = Flask(__name__) api = Api(application) properties = { 'current.dir': os.path.abspath(os.getcwd()), 'package.dir': os.path.dirname(snapsnare.__file__), 'home.dir': str(Path.home()), 'app.name': 'snapsnare' } ds = utils.load_json(properties, 'snapsnare-ds.json') connector = ConnectorFactory.create_connector(ds) application.connector = connector application.properties = properties # set the secret, jwt uses this. # every time the rest server start a new secret is created. Sessions do not survive a reboot. application.config['SECRET_KEY'] = uuid4().hex # set the upload folder application.config['UPLOAD_FOLDER'] = os.path.join(properties['package.dir'], 'static') # initialize the logger utils.load_logger(properties, 'log.json', 'snapsnare')
message['From'] = account message['To'] = recipients message['Subject'] = subject message.attach(MIMEText(content, 'html')) server = smtplib.SMTP_SSL(smtp_host, smtp_port) server.ehlo() server.login(account, password) server.sendmail(account, recipients, message.as_string()) server.close() properties = { 'current.dir': os.path.abspath(os.getcwd()), 'package.dir': os.path.dirname(snapsnare.__file__), 'home.dir': str(Path.home()), 'app.name': 'snapsnare' } settings = utils.load_json(properties, 'snapsnare.json') credentials = settings['gmail'] snapsnare = settings['snapsnare'] uuid = "80c1fbd2-0c45-49da-9b24-b8666cd118f8" host = snapsnare['host'] content = "<img src=http://snapsnare.org/static/snapsnare.png><br>Er is een account voor je aangemaakt.<br> Ga naar <a href=http://{host}/activate?uuid={uuid}>http://{host}/activate?uuid={uuid}</a> om je account te activeren." content = content.replace("{host}", host) content = content.replace("{uuid}", uuid) send_email(credentials, '*****@*****.**', "activate your account", content)
def show(): connector = current_app.connector if request.method == 'GET': properties = current_app.properties section_repository = SectionRepository(connector) sections = section_repository.list_by(active=1, order_by='id') return render_template('register/register.html', sections=sections) if request.method == 'POST': register_repository = RegistrationRepository(connector) role_repository = RoleRepository(connector) template_repository = TemplateRepository(connector) username = request.form['username'] password = request.form['password'] first_name = request.form['first_name'] last_name = request.form['last_name'] nickname = request.form['nickname'] registered = register_repository.is_registered(username) if registered: connector.close() flash('This account is already registered.', 'danger') return redirect(url_for('register.show')) role = role_repository.find_by(role='user', active=1) registration = { 'username': username, 'password': hasher.sha256(password), 'uuid': str(uuid4()), 'first_name': first_name, 'last_name': last_name, 'nickname': nickname, 'rle_id': role['id'] } id_ = register_repository.insert(registration) print("registration created with id ", id_) properties = current_app.properties settings = utils.load_json(properties, 'snapsnare.json') credentials = settings['gmail'] snapsnare = settings['snapsnare'] host = snapsnare['host'] template = template_repository.find_by(template='activate') content = template['content'] content = content.replace("{host}", host) content = content.replace("{uuid}", registration['uuid']) connector.commit() connector.close() gmail.send_email(credentials, registration['username'], "Activate your account on snapsnare.org", content) flash( 'Your account is successfully registered, an activation email is send.', 'success') return redirect(url_for('register.show'))