def api_collaborator_new(webhook_id, user_id): # login user login_user_id = RequestUtil.get_login_user().get('id', '') if login_user_id == user_id: return ResponseUtil.standard_response(0, '`%s` is Creator!' % user_id) if not AuthUtil.has_admin_auth(login_user_id, webhook_id): return ResponseUtil.standard_response(0, 'Permission deny!') collaborator = Collaborator.query.filter_by(webhook_id=webhook_id, user_id=user_id).first() # not exist if collaborator: return ResponseUtil.standard_response(0, 'Collaborator exist!') # 开始添加 user = User.query.get(user_id) if not user: user = User(id=user_id, name=user_id) user.save() collaborator = Collaborator(webhook_id=webhook_id, user=user) collaborator.save() return ResponseUtil.standard_response(1, collaborator.dict())
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, name=form.username.data, password=form.password.data, registration_time=datetime.utcnow(), last_seen_time=datetime.utcnow()) user.confirmed = False user.avatar_hash = hashlib.md5( form.email.data.encode('utf-8')).hexdigest() db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token) flash('A confirmation email has been sent to you by email.') #flash('log in please!') return redirect(url_for('auth.login')) return render_template('auth/register.html', form=form)
def github_authorized(oauth_token): if oauth_token is None: flash("Authorization failed.") return redirect(url_for('index')) session['oauth_token'] = oauth_token me = github.get('user') user_id = me['login'] # is user exist user = User.query.get(user_id) if user is None: # not exist, add user = User(id=user_id) # update github user information user.last_login = DateUtil.now_datetime() user.name = me.get('name', user_id) user.location = me.get('location', '') user.avatar = me.get('avatar_url', '') user.save() RequestUtil.login_user(user.dict()) return redirect(url_for('index'))
def register(username, password, email): # username = request.json.get('úsername') # password = request.json.get('password') # email = request.json.get('email') if User.query.filter_by(username=username).first() is not None: return ResponseUtil.standard_response(0, 'user is exist') user = User(username=username, email=email) user.hash_password(password) user.save() return ResponseUtil.standard_response(1, user.dict())
def regist_user(username, password, email='', wx_openid=''): try: user = get_user(username=username) or None if user is None: user = User(username, password, email, wx_openid) db.session.add(user) db.session.commit() return user else: return user except: return None