def put(self, username): user = self.authenticate() if user: new_user = request.get_json(force=True) user.name = new_user['name'] user.username = new_user['username'] user.password = Crypt.hash_sha256(new_user['password']) db.session.commit() return json.jsonify(user.as_dict()) raise InvalidUsage()
def put(self, user_id): auth_key = request.args.get('key') user = User.authenticate(user_id, auth_key) if user: new_user = request.get_json(force=True) user.name = new_user['name'] user.login = new_user['login'] user.password = Crypt.hash_sha256(new_user['password']) db.session.commit() return json.jsonify(user.as_dict()) return json.jsonify({})
def post(self): supposed_user = request.get_json(force=True) if supposed_user: user = User() user.name = supposed_user['name'] user.login = supposed_user['login'] user.password = Crypt.hash_sha256(supposed_user['password']) user.auth_key = Auth.get_new_key() db.session.add(user) db.session.commit() if user.user_id: return json.jsonify(user.as_dict()) return json.jsonify({})
def post(self): supposed_user = request.get_json(force=True) user = User.query.filter_by(username=supposed_user[ 'username']).first_or_404() if user and user.password == Crypt.hash_sha256(supposed_user['password']): token = jwt.encode({ 'exp': time.time() + 60 * 60 * 24 * 7, 'user_id': user.user_id, 'username': user.username, 'name': user.name }, config.SECRET_KEY, algorithm='HS256') return json.jsonify({'token': token}) raise InvalidUsage("Username and password does not match.")
def post(self): supposed_user = request.get_json(force=True) has_username_taken = User.query.filter_by( username=supposed_user['username']).first() if supposed_user and not has_username_taken: user = User() user.name = supposed_user['name'] user.username = supposed_user['username'] user.password = Crypt.hash_sha256(supposed_user['password']) db.session.add(user) db.session.commit() if user.user_id: return json.jsonify(user.as_dict()) raise InvalidUsage()
def post(self): supposed_user = request.get_json(force=True) user = User.query.filter_by(login=supposed_user['login']).first_or_404() if user and user.password == Crypt.hash_sha256(supposed_user['password']): return json.jsonify(user.as_dict()) return json.jsonify({})