def register(): form = RegistrationForm(csrf_enabled=False) if request.method == 'POST' and form.validate(): user = User() user.id = form.id.data user.first_name = form.first_name.data user.last_name = form.last_name.data user.password = form.password.data user.email = form.email.data user.contact_no = form.contact_no.data user.branch = form.branch.data user.profile_type = request.form['profile_type'] profile_pic = request.files['profile_pic'] if profile_pic: profile_pic_extension = ctrl.get_extension_of_file(profile_pic.filename) user.profile_pic_extension = profile_pic_extension file_op.save_profile_pic(profile_pic, user.id) if user.profile_type != 'P': ctrl.mkdir_p(os.path.join(app.config['SOLUTION_FILES_DEST'], user.id)) user.is_active = 'Y' db_session = get_db_session() insert_to_db(db_session, user) return render_template('forms/registration_success.html') return render_template('forms/register.html', form=form)
def http_post(self, properties, page): if page == "1": email = properties.post["registerEmail"] user = User(email=email) user.put() properties.session["user"] = user.key().id() return '{ "success": true, "target": "/register/2" }' elif page == "2": user = User.get_by_id(properties.session.get("user")) if user.email != properties.post["email"]: return '{ "success": false, "error": "Email address entered incorrectly" }' if len(properties.post["password"]) < 4: return '{ "success": false, "error": "Password must be at least 4 characters" }' user.password = security.hash_password(properties.post["password"], "sha1") user.firstName = properties.post["firstName"] user.lastName = properties.post["lastName"] user.address1 = properties.post["address1"] user.address2 = properties.post["address2"] user.zip = properties.post["zip"] user.state = properties.post["state"] user.put() return '{ "success": true, "target": "/register/3" }' elif page == "3": user = User.get_by_id(properties.session.get("user")) try: if properties.post["years"] != "": user.years = int(properties.post["years"]) except ValueError: return '{ "success"; false, "error": "Years must be valid number" }' user.has_served = "not_military" not in properties.post user.honorable_discharge = ( "honorable_discharge" in properties.post and properties.post["honorable_discharge"] == "yes" ) user.branch = properties.post["service_name"] user.duty_status = properties.post["duty_status"] user.occupations = properties.post["occupations"] user.deployments = properties.post["deployments"] user.highest_rank = properties.post["highest_rank"] user.put() return '{ "success": true, "target": "/register/4" }' elif page == "4": user = User.get_by_id(properties.session.get("user")) try: if properties.post["occupation1_time"] != "": user.occupation1Time = int(properties.post["occupation1_time"]) if properties.post["occupation2_time"] != "": user.occupation2Time = int(properties.post["occupation2_time"]) if properties.post["occupation3_time"] != "": user.occupation3Time = int(properties.post["occupation3_time"]) if properties.post["occupation4_time"] != "": user.occupation4Time = int(properties.post["occupation4_time"]) except ValueError: return '{ "success"; false, "error": "Years must be valid number" }' user.education = properties.post["education"] user.certifications = properties.post["certifications"] user.occupation1 = properties.post["occupation1"] user.occupation2 = properties.post["occupation2"] user.occupation3 = properties.post["occupation3"] user.occupation4 = properties.post["occupation4"] user.put() return '{ "success": true, "target": "/register/5" }' elif page == "5": return '{ "success": true, "target": "/" }'