- Timestamp:
- Feb 29, 2020, 4:48:24 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- a88607b
- Parents:
- 306f18a
- git-author:
- Joachim Langenbach <joachim.langenbach@…> (02/29/20 16:01:11)
- git-committer:
- Joachim Langenbach <joachim.langenbach@…> (02/29/20 16:48:24)
- Location:
- src
- Files:
-
- 1 added
- 10 edited
-
mapservice-webclient/src/app/user/register.component.html (modified) (2 diffs)
-
mapservice-webclient/src/app/user/register.component.ts (modified) (1 diff)
-
mapservice/codegen/code_generator (modified) (1 diff)
-
mapservice/codegen/templates/__init__.mustache (modified) (1 diff)
-
mapservice/codegen/templates/__main__.mustache (modified) (2 diffs)
-
mapservice/codegen/templates/requirements.mustache (modified) (1 diff)
-
mapservice/openapi.yaml (modified) (4 diffs)
-
mapservice/src/server_impl/Config.py (modified) (3 diffs)
-
mapservice/src/server_impl/controllers/UsersController.py (modified) (5 diffs)
-
mapservice/src/server_impl/database/Model.py (modified) (4 diffs)
-
mapservice/templates/activation_mail.html (added)
Legend:
- Unmodified
- Added
- Removed
-
src/mapservice-webclient/src/app/user/register.component.html
r306f18a rbd0cb38 2 2 <div class="header"> 3 3 <h1>Register</h1> 4 <alert></alert> 4 5 </div> 5 6 <div class="content"> … … 35 36 </div> 36 37 </div> 38 <div class="pure-control-group"> 39 <label for="password">E-Mail</label> 40 <input type="email" formControlName="email" [ngClass]="{ 'is-invalid': submitted && f.email.errors }" /> 41 <div *ngIf="submitted && f.email.errors" class="invalid-feedback"> 42 <div *ngIf="f.email.errors.required">E-Mail is required</div> 43 </div> 44 </div> 45 <div class="pure-control-group"> 46 <label for="licenseAccepted"></label> 47 <input id="licenseAccepted" type="checkbox" formControlName="licenseAccepted" [ngClass]="{ 'is-invalid': submitted && f.licenseAccepted.errors }"> 48 I agree to upload all date under the <a href="https://www.opendatacommons.org/licenses/odbl/summary/index.html" target="_blank">Open Data Commons Open Database License (ODbL)</a> 49 <div *ngIf="submitted && f.licenseAccepted.errors" class="invalid-feedback"> 50 <div *ngIf="f.licenseAccepted.errors.required">Accepting the license is required</div> 51 </div> 52 </div> 37 53 <div class="pure-controls"> 38 54 <button [disabled]="loading" class="pure-button pure-button-primary button-add">Register</button> -
src/mapservice-webclient/src/app/user/register.component.ts
r306f18a rbd0cb38 34 34 lastName: ['', Validators.required], 35 35 username: ['', Validators.required], 36 password: ['', [Validators.required, Validators.minLength(6)]] 36 password: ['', [Validators.required, Validators.minLength(6)]], 37 email: ['', Validators.required], 38 licenseAccepted: ['', Validators.required] 37 39 }); 38 40 } -
src/mapservice/codegen/code_generator
r306f18a rbd0cb38 25 25 cp -a ../../../common/resources/* static/resources/ 26 26 cp -a ../../../common/icon/* static/resources/ 27 mkdir -p templates 28 cp -a ../../templates/* templates/ 27 29 28 30 echo "Generating backend and client API code" -
src/mapservice/codegen/templates/__init__.mustache
r306f18a rbd0cb38 1 import connexion 2 from flask_cors import CORS 3 from flask_mail import Mail 4 5 app = connexion.App(__name__, specification_dir='./openapi/') 6 application = app.app 7 CORS(application) 8 mail = Mail() -
src/mapservice/codegen/templates/__main__.mustache
r306f18a rbd0cb38 6 6 {{/supportPython2}} 7 7 8 import connexion9 from flask_cors import CORS10 #from flask import render_template11 8 import flask 12 9 from sqlalchemy import event 13 10 14 from {{packageName}} import encoder 15 11 from {{packageName}} import encoder, app, application, mail 16 12 from {{packageName}}.server_impl.database.Model import db, User, ApiKey, db_setup, db_test_setup 17 18 13 from {{packageName}}.server_impl.ValidatorWorkaround import ValidatorWorkaround 19 20 app = connexion.App(__name__, specification_dir='./openapi/')21 application = app.app22 CORS(application)23 14 24 15 @application.before_first_request … … 46 37 47 38 db.init_app(application) 39 mail.init_app(application) 48 40 49 41 app.run(port={{serverPort}}) -
src/mapservice/codegen/templates/requirements.mustache
r306f18a rbd0cb38 8 8 flask-sqlalchemy 9 9 flask-cors 10 flask-mail 10 11 shapely 11 12 geoalchemy2 -
src/mapservice/openapi.yaml
r306f18a rbd0cb38 792 792 activated: 793 793 type: boolean 794 licenseAccepted: 795 type: boolean 794 796 apiKeys: 795 797 $ref: '#/components/schemas/apiKeys' … … 808 810 password: 809 811 type: string 812 licenseAccepted: 813 type: boolean 810 814 required: 811 815 - username … … 814 818 - lastName 815 819 - password 820 - licenseAccepted 816 821 Water: 817 822 title: Water … … 1158 1163 lastName: Roe 1159 1164 password: sdfl.1238_ASDkeil? 1165 licenseAccepted: true 1160 1166 Water: 1161 1167 value: -
src/mapservice/src/server_impl/Config.py
r306f18a rbd0cb38 21 21 SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db' 22 22 SQLALCHEMY_TRACK_MODIFICATIONS = False 23 MAIL_SERVER = 'localhost' 24 MAIL_PORT = 25 25 MAIL_DEFAULT_SENDER = 'GNUBoat Mapservice <gnuboat@engsas.de>' 26 MAPSERVICE_WEBCLIENT = '/' 23 27 24 28 class ProductionConfig(Config): … … 28 32 DEBUG = True 29 33 CREATE_TEST_DATABASE = True 34 MAPSERVICE_WEBCLIENT = 'http://localhost:8081' 30 35 31 36 class TestingConfig(Config): … … 33 38 DEBUG = False 34 39 CREATE_TEST_DATABASE = True 40 MAPSERVICE_WEBCLIENT = 'http://localhost:8081' -
src/mapservice/src/server_impl/controllers/UsersController.py
r306f18a rbd0cb38 1 1 ''' 2 Copyright (C) 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.2 Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 3 3 4 4 This program is free software: you can redistribute it and/or modify … … 19 19 import datetime 20 20 import hashlib 21 import re 22 import flask 23 from flask import request, render_template 24 from flask_mail import Message 21 25 26 from openapi_server import mail 22 27 from ..database.Model import User, ApiKey, db 23 28 from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound 24 29 30 mail_regex = re.compile('[^@]+@[^@]+\.[^@]+') 31 25 32 def users_activate(activationCode): 26 33 user = User.query.filter_by(activation_code=activationCode).all() 34 35 webclient = flask.current_app.config['MAPSERVICE_WEBCLIENT'] 36 27 37 if len(user) != 1: 28 38 return 'Bad Request', 302, {'Location': 'activation_failed.html'} … … 31 41 user.activated = True 32 42 user.activation_code = "" 33 return 'Success', 302, {'Location': 'activation_succeeded.html'} 43 db.session.commit() 44 return 'Success', 302, {'Location': '{}/login'.format(webclient)} 34 45 35 46 def users_api_key_create(): … … 66 77 raise MapserviceUnauthorized 67 78 79 return user_to_dict(user) 80 81 def users_register(user_creation): 82 if user_creation is None: 83 raise MapserviceBadRequest(detail='No data specified') 84 if user_creation.username is None or user_creation.username == "": 85 raise MapserviceBadRequest(detail='No username given') 86 if user_creation.password is None or user_creation.password == "": 87 raise MapserviceBadRequest(detail='No password given') 88 if user_creation.first_name is None or user_creation.first_name == "": 89 raise MapserviceBadRequest(detail='No first name given') 90 if user_creation.last_name is None or user_creation.last_name == "": 91 raise MapserviceBadRequest(detail='No last name given') 92 if user_creation.email is None or user_creation.email == "": 93 raise MapserviceBadRequest(detail='No email given') 94 if not mail_regex.match(user_creation.email): 95 raise MapserviceBadRequest(detail='Email contains more than one @, no @ or no .') 96 if user_creation.license_accepted is None or not user_creation.license_accepted: 97 raise MapserviceBadRequest(detail='You must accept the license to register an account') 98 99 # add user to the database 100 user = User.factory(user_creation.username, user_creation.password, user_creation.email) 101 user.first_name = user_creation.first_name 102 user.last_name = user_creation.last_name 103 user.license_accepted = user_creation.license_accepted 104 db.session.add(user) 105 db.session.commit() 106 107 # send activation mail 108 activation_url = '{}/activate/{}'.format(request.base_url, user.activation_code) 109 110 message = Message("Activate your GNUBoat account", recipients=[user.email]) 111 message.body = 'Hello {},\nthank you for support the project with your own measurings. To activate your GNUBoat account, visit {}.\nKind regards,\nYour GNUBoat team'.format(user.first_name, activation_url) 112 message.html = render_template('activation_mail.html', first_name=user.first_name, activation_url=activation_url) 113 mail.send(message) 114 115 return user_to_dict(user) 116 117 def user_to_dict(user): 68 118 # create user dict and remove not needed entries 69 119 result = user.to_dict() … … 76 126 for apiKey in user.apikeys: 77 127 result['apiKeys'].append(apiKey.key) 78 79 128 return result 80 81 def users_register(user_creation):82 print(user_creation)83 84 return 'Not Found', 500 -
src/mapservice/src/server_impl/database/Model.py
r306f18a rbd0cb38 53 53 activation_code = db.Column(db.String(255), default='1234') 54 54 #activation_code = db.Column(db.String(255), server_default=text('LEFT(MD5(NOW()), 50)')) 55 license_accepted = db.Column(db.Boolean(), default=False) 55 56 56 57 def to_dict(user): … … 63 64 'lastName': "", 64 65 'activated': user.activated, 65 66 'licenseAccepted': user.license_accepted, 66 67 } 67 68 if user.first_name is not None: … … 382 383 test_user_john = query[0] 383 384 else: 384 test_user_john = User.factory('john', 'testpass2', 'john@example.org' )385 test_user_john = User.factory('john', 'testpass2', 'john@example.org', license_accepted=True) 385 386 test_user_john.activation_code = 'dac9630aec642a428cd73f4be0a03569' 386 387 db.session.add(test_user_john) … … 392 393 test_user_jane = query[0] 393 394 else: 394 test_user_jane = User.factory('jane', 'testpass', 'jane@example.org' )395 test_user_jane = User.factory('jane', 'testpass', 'jane@example.org', license_accepted=True) 395 396 test_user_jane.activated = True 396 397 test_user_jane.first_name = 'Jane'
Note:
See TracChangeset
for help on using the changeset viewer.
