def post(self): user = Users(**request.json) user.set_password(request.json['password']) user.add() expires = datetime.timedelta(days=7) access_token = create_access_token(identity=str(user.id), expires_delta=expires) return {'token': access_token}, 200
def post(self): try: data = parserU.parse_args() if data['dob'] == None: return {'message': 'dob field cannot be blank'}, 400 age = calculate_age(parse(data['dob'])) if age < 18: return { 'message': 'User {} should be greater 18'.format(data['username']) }, 400 new_user = Users(username=data['username'], password=Users.generate_hash(data['password']), dob=data['dob']) new_user.add() access_token = create_access_token(identity=data['username']) refresh_token = create_refresh_token(identity=data['username']) return { 'message': 'User {} was created'.format(data['username']), 'access_token': access_token, 'refresh_token': refresh_token }, 200 except: return {'message': 'Something went wrong'}, 500
def add(self, **post): user = Users.new(name="", email="", username="", password="") meta, auth_meta = self.get_meta() if post: fields = ['name', 'username', 'email', 'user_group'] data = self._get_data('user', fields, post) self._set_data(user, data) auth_meta = self._get_data('auth_meta', meta, post) user.set_meta_data(auth_meta) if user.validates() and Users.add(user): cherrypy.session['flash'] = "Jail Type successfully added." raise cherrypy.HTTPRedirect("/users") cherrypy.session['flash'] = "Invalid data." user.password = "" user.password_repeat = "" env=dict(user = user, meta=meta, auth_meta=auth_meta) return self.render("/users/add.html", crumbs=self.crumbs, **env)