def user_add(): """Page with user add route.""" route_to = url_for('user_add') form = UserAddForm(request.form) if form.validate_on_submit(): newuser = User() newuser.name = form.name.data newuser.alias = form.alias.data newuser.role_id = form.role_id.data newuser.email = form.email.data newuser.password = form.password.data db.session.add(newuser) db.session.commit() subject = "Add User" msg = Message(app.config['ADMIN_MAIL_SUBJECT_PREFIX'] + ' ' + subject, sender=app.config['ADMIN_MAIL_SENDER'], recipients=[newuser.email]) msg.body = """ From: %s to <%s> Email: %s Name: %s Alias: %s """ % (app.config['ADMIN_MAIL_SUBJECT_PREFIX'], newuser.email, newuser.email, newuser.name, newuser.alias) mail.send(msg) flash("User added and notification", category="success") return redirect(url_for('user_page')) return render_template('user_add.html', form=form, route_to=route_to)
def sign_up(): data_form = request.json mobile = data_form.get('mobile', None) password1 = data_form.get('password1', None) password2 = data_form.get('password2', None) verify_code = data_form.get('verify_code', None) if mobile and password1 and password2 and verify_code: if password1 != password2: return jsonify({ "success": False, "message": "password is not correct" }) if verify_code != int(session.get(str(mobile), None)): return jsonify({ "success": False, "message": "verify_code is not correct" }) if User.find_one(mobile=int(mobile)): return jsonify({ "success": False, "message": "mobile is already exist" }) user = User(mobile, password1) user.save() login_user(load_user(user.id), remember=True) return jsonify({"success": True, 'redirect_url': 'admin_panel'}) else: return jsonify({ "success": False, "message": "data form is not correct" })
def post(self): data = UserRegister.parser.parse_args() if User.find_by_username(data['username']): return {'message': f"user {data['username']} already exists"}, 400 user = User(username=data['username'], password=data['password']) user.add_user() return { 'username': data['username'], 'password': data['password'] }, 201
category = Category(category='Road accident', favicon='') category1 = Category(category='Infrastructure accident', favicon='') category2 = Category(category='Another accident', favicon='') category3 = Category(category='Accident with animals', favicon='') status1 = Status(status="new") status2 = Status(status="on moderation") status3 = Status(status="open") status4 = Status(status="closed") status5 = Status(status="deleted") status6 = Status(status="pending close") user1 = User(name='Bob', alias='Bobby', email='*****@*****.**', password='******', role_id='1') user2 = User(name='Mark', alias='Marky', email='*****@*****.**', password='******', role_id='2') user3 = User(name='Maria', alias='Mary', email='*****@*****.**', password='******', role_id='3') user4 = User(name='Petya', alias='Petya', email='*****@*****.**',