def home(): print "config.AUTHENTICATE {}".format(config.AUTHENTICATE) if config.AUTHENTICATE: return render_template('index.html', login_form=LoginForm(), create_form=CreateAccountForm()) else: email = 'default' password = '******' access_key_id = config.AWS_ID secret_access_key = config.AWS_KEY aws_bucket_name = config.AWS_BUCKET_NAME next_backend_global_host = config.NEXT_BACKEND_GLOBAL_HOST if not User.objects(email=email): user = User(email=email, access_key_id=access_key_id, secret_access_key=secret_access_key, aws_bucket_name=aws_bucket_name, next_backend_global_host=next_backend_global_host) user.set_password(password) user.save() else: user = User.objects(email=email).first() login_user(user, remember=True) return redirect(url_for('dashboard._dashboard'))
def create(): create_form = CreateAccountForm(request.form) if create_form.validate_on_submit(): print "form data",create_form.new_email.data new_email = create_form.new_email.data new_password = create_form.new_password.data confirm_password = create_form.confirm_password.data print User.objects() if User.objects(email=new_email).count() == 0: if new_password == confirm_password: # Set the hashed password on the user. user = User(email=new_email) user.set_password(new_password) user.save() login_user(user, remember=True) return redirect(url_for('dashboard._dashboard')) else: flash("Passwords don't match!", "create_error") return redirect('#create') else: flash("Username exists!", "create_error") return redirect('#create') # login form is not valid return render_template('index.html', login_form=LoginForm(), create_form=create_form)
def create(): create_form = CreateAccountForm(request.form) if create_form.validate_on_submit(): print "form data",create_form.new_email.data new_email = create_form.new_email.data new_password = create_form.new_password.data confirm_password = create_form.confirm_password.data print User.objects() if User.objects(email=new_email).count() == 0: if new_password == confirm_password: # Set the hashed password on the user. user = User(email=new_email) user.set_password(new_password) user.save() login_user(user, remember=True) return redirect(url_for('dashboard._dashboard')) else: flash("Passwords don't match!", "create_error") return redirect('#create') else: flash("Username exists!", "create_error") return redirect('#create') # login form is not valid return render_template('index.html', login_form=LoginForm(), create_form=create_form)
def add_user(request): '''用户添加''' context = {} context['add_user'] = True if request.method == 'GET': #获得职位信息 positions = Position.objects.all() position_list = [] for position in positions: position_list.append({ 'id': position.id, 'name': position.name, }) #获得部门信息 departments = Department.objects.all() department_list = [] for department in departments: department_list.append({ 'id': department.id, 'name': department.name, }) if department_list: context['department_list'] = department_list if position_list: context['position_list'] = position_list else: errorList = [] username = request.POST['username'] username_zh = request.POST.get('username_zh', '') mobile = request.POST['mobile'] password = request.POST['password'] confirm_password = request.POST['confirm_password'] department = request.POST.get('department', '') position = request.POST.get('position', '') chief = request.POST.get('chief', '') short_phone = request.POST.get('short_phone', '') if password != confirm_password: errorList.append({'error': u'密码不一致'}) else: user = User() if username: user.username = username if username_zh: user.username_zh = username_zh if mobile: user.mobile = mobile if department: user.department = Department.objects.get(id=int(department)) if position: user.position = Position.objects.get(id=int(position)) if short_phone: user.short_phone = short_phone user.set_password(password) try: user.full_clean() user.save() except ValidationError as e: # Do something based on the errors contained in e.message_dict. # Display them to a user, or handle them programmatically. errKeys = e.message_dict.keys() for errKey in errKeys: errorList.append({'error': e.message_dict[errKey][0]}) if errorList: context['errorList'] = errorList return render(request, 'base/settings.html', context)