def test_delete_person(self): with app.app_context(): person = Person.query.filter_by(first_name="Unit").first() person_id = serializer.dumps(person.id) tester = app.test_client(self) response = tester.delete('/delete/' + person_id) data = json.loads((response.data).decode('utf-8')) self.assertEqual(data['status'], 1)
def get_all_users(): user = mongo.db.users.find_one({'name': g.user}, {"_id": 0, "token": 0}) token = serializer.dumps({'username': user['name']}) #mongo.db.users.update({'name': 'ww'},{'$set':{'token': token}}) return jsonify({ 'username': user['name'], 'token': token.decode('ascii'), 'code': 20000 })
def sendEmail(self): email = request.form.get('email') token = serializer.dumps(email, salt='email-confirm') msg = Message('Confirm Email To Reset Password', sender='*****@*****.**', recipients=[email]) link = url_for('confirm_email', token=token, _external=True) msg.body = 'Kindly follow the link to change your password {}'.format( link) mail.send(msg) return 'Kindly check your email <strong>{}</strong> to continue...'.format( email)
def hello(): from run import app print(app.root_path) print(serializer.dumps({'username': '******'})) return 'hello,world'
def __init__(self, username): self.username = username self.session_token = serializer.dumps([username])
def generate_auth_token(self): return serializer.dumps({'Account': self.Account})
def register(): data = request.json if data is None or data['username'] is None or data[ 'email'] is None or data['first_name'] is None or data[ 'last_name'] is None or data['password'] is None: return jsonify({'register': 'Error'}), 401 check = User.get().filter_by(name=data['username']).first() if check is not None: return jsonify({'register': 'Username taken'}), 401 check = User.get().filter_by(email=data['email']).first() if check is not None: return jsonify({'register': 'Email taken'}), 401 token = serializer.dumps(data['email'], salt='register-confirm') if request.environ.get('HTTP_X_FORWARDED_FOR') is None: userIP = request.environ['REMOTE_ADDR'] else: userIP = request.environ['HTTP_X_FORWARDED_FOR'] userIP = userIP.split(',')[0] if userIP == "127.0.0.1": userIP = "86.123.189.180" resp = requests.get( ('https://www.iplocate.io/api/lookup/{}').format(userIP)) userLoc = resp.json() iso_code = userLoc['country_code'] api_2 = requests.get( ("https://restcountries.eu/rest/v2/alpha/{}").format(iso_code)) result_2 = api_2.json() index = str(db.session.execute(Sequence('users_id_seq'))) msg = Message('Confirm Email Registration', sender='*****@*****.**', recipients=[data['email']]) link = 'https://new-app.dev/?email={}&token={}'.format( data['email'], token) msg.html = render_template('email_register.html', register=link, email='*****@*****.**') mail.send(msg) check_loc = Ip_Location.get().filter_by(ip=userIP).first() check_lang = Languages.get().filter_by( code=result_2['languages'][0]['iso639_1']).first() os.umask(0) os.mkdir(config.get('ROOT_PATH') + '/static/users/' + index) if check_loc is None: ip_loc_index = str(db.session.execute(Sequence('ip_location_id_seq'))) loc_index = str(db.session.execute(Sequence('location_id_seq'))) new_user_json = { "id": index, "confirmed": False, "email": data['email'], "info": { "avatar_img": CreateAvatar({ "id": index, "first_name": data['first_name'], "last_name": data['last_name'] }), "user": index, "first_name": data['first_name'], "last_name": data['last_name'] }, "pers": { "user": index }, "name": data['username'], "role_id": 2, "status_id": 2, "password": data["password"] } if check_lang is None: new_user_json["language"] = { "code": result_2['languages'][0]['iso639_1'], "name": result_2['languages'][0]['name'], } else: new_user_json["language"] = NewLanguageSchema().dump(check_lang) if check_loc is None: new_user_json["location"] = { "ip": userIP, "id": ip_loc_index, "location": { "id": loc_index, "city": userLoc['city'], "country": userLoc['country'], "flag": result_2['languages'][0]['iso639_1'], "iso": userLoc['country_code'], "latitude": str(userLoc['latitude']), "longitude": str(userLoc['longitude']), } } else: new_user_json["location"] = NewLocationSchema().dump(check_loc) new_user = NewUserSchema().load(new_user_json) new_user.add() return make_response(jsonify({'register': 'success'}), 200)
def index(title="Index page"): persons = Person.query.all() for person in persons: person.id = serializer.dumps(person.id) return render_template('index.html', persons=persons, title=title)