def post(self): """Creates new user account if provided valid arguments""" parser = reqparse.RequestParser() parser.add_argument('email', type=UserValidator.create('unique_email'), required=True) parser.add_argument('username', type=UserValidator.create('unique_username')) parser.add_argument('password', type=UserValidator.create('password')) parser.add_argument('remember', type=inputs.boolean, default=False) args = parser.parse_args() user_db = auth.create_user_db( auth_id=None, name='', username=args.username, email=args.email, verified=True if not config.CONFIG_DB.verify_email else False, password=args.password ) user_db.put() if config.CONFIG_DB.verify_email: task.verify_user_email_notification(user_db) return make_empty_ok_response() # if users don't need to verify email, we automaticaly signin newly registered user auth.signin_user_db(user_db, remember=args.remember) return user_db.to_dict(include=User.get_private_properties())
def post(self): """Sends email with token for resetting password to an user""" parser = reqparse.RequestParser() parser.add_argument('email', type=UserValidator.create('existing_email')) args = parser.parse_args() user_db = User.get_by('email', args.email) task.reset_password_notification(user_db) return make_empty_ok_response()
def put(self, key): """Updates user's properties""" update_properties = ['created_at', 'title', 'location', 'type_', 'description', 'how_to_apply', 'company', 'company_url', 'company_logo', 'url'] new_data = _.pick(request.json, update_properties) g.model_db.populate(**new_data) g.model_db.put() return make_empty_ok_response()
def put(self, key): """Updates user's properties""" update_properties = ['name', 'bio', 'email', 'location', 'facebook', 'github', 'gplus', 'linkedin', 'twitter', 'instagram'] if auth.is_admin(): update_properties += ['verified', 'active', 'admin'] new_data = _.pick(request.json, update_properties) g.model_db.populate(**new_data) g.model_db.put() return make_empty_ok_response()
def post(self): """Sends feedback email to admin""" if not config.CONFIG_DB.feedback_email: return abort(418) parser = reqparse.RequestParser() parser.add_argument('message', type=ArgumentValidator.create('feedback'), required=True) parser.add_argument('email', type=UserValidator.create('email', required=False)) args = parser.parse_args() body = '%s\n\n%s' % (args.message, args.email) kwargs = {'reply_to': args.email} if args.email else {} task.send_mail_notification('%s...' % body[:48].strip(), body, **kwargs) return make_empty_ok_response()
def post(self, key): """Changes user's password""" parser = reqparse.RequestParser() parser.add_argument('currentPassword', type=UserValidator.create('password', required=False), dest='current_password') parser.add_argument('newPassword', type=UserValidator.create('password'), dest='new_password') args = parser.parse_args() # Users, who signed up via social networks have empty password_hash, so they have to be allowed # to change it as well if g.model_db.password_hash != '' and not g.model_db.has_password(args.current_password): raise ValueError('Given password is incorrect.') g.model_db.password_hash = util.password_hash(args.new_password) g.model_db.put() return make_empty_ok_response()
def put(self, key): """Updates user's properties""" update_properties = [ 'name', 'bio', 'email', 'location', 'facebook', 'github', 'gplus', 'linkedin', 'twitter', 'instagram' ] if auth.is_admin(): update_properties += ['verified', 'active', 'admin'] new_data = _.pick(request.json, update_properties) g.model_db.populate(**new_data) g.model_db.put() return make_empty_ok_response()
def post(self): new_data = _.pick(request.json, Crumb.get_public_properties()) crumb = Crumb() crumb.populate(**new_data) mapbox_params = { 'url': 'https://api.mapbox.com/geocoding/v5/mapbox.places', 'token': 'pk.eyJ1Ijoic2lkaGFydGEiLCJhIjoiY2ltczg2OW1yMDFpNHZsbTR6MWs5ZHlwbSJ9.T5h2oS8vItUFM9__uoRvaA', 'lng': crumb.lng, 'lat': crumb.lat } mapbox_url = '{url}/{lng},{lat}.json?access_token={token}&types=address'.format(**mapbox_params) response = json.load(urllib2.urlopen(mapbox_url)) addresses = response['features'] if addresses != None and len(addresses): crumb.place = addresses[0]['place_name'] crumb.put() return make_empty_ok_response()
def post(self, key): """Changes user's password""" parser = reqparse.RequestParser() parser.add_argument('currentPassword', type=UserValidator.create('password', required=False), dest='current_password') parser.add_argument('newPassword', type=UserValidator.create('password'), dest='new_password') args = parser.parse_args() # Users, who signed up via social networks have empty password_hash, so they have to be allowed # to change it as well if g.model_db.password_hash != '' and not g.model_db.has_password( args.current_password): raise ValueError('Given password is incorrect.') g.model_db.password_hash = util.password_hash(args.new_password) g.model_db.put() return make_empty_ok_response()
def post(self): """Generates mock data for development purposes""" if not DEVELOPMENT: abort(404) UserFactory.create_batch(20) #CollectionFactory.create(30,"*****@*****.**") CollectionFactory.create_private() CollectionFactory.create(5,None) CollectionFactory.create(10,"random", start_nr=6) # Create Big Mountain collection user_key = auth.current_user_key() big_mt_key=model.Collection.create(name="Big Mountain", creator=user_key, avatar_url='https://pixabay.com/static/uploads/photo/2015/09/02/12/27/matterhorn-918442_960_720.jpg' ) CollectionFactory.add_users(max_collections=50,user_min=2,user_max=10) model.Collection.create_or_update(key=big_mt_key,description="Something in the mountains") WayPointFactory.create(30) WayPointFactory.create(5,1000,4,[big_mt_key]) return make_empty_ok_response()
def put(self, key): """Updates user's properties""" update_properties = [ "name", "bio", "email", "location", "facebook", "github", "gplus", "linkedin", "twitter", "instagram", ] if auth.is_admin(): update_properties += ["verified", "active", "admin"] new_data = _.pick(request.json, update_properties) g.model_db.populate(**new_data) g.model_db.put() return make_empty_ok_response()
def post(self): new_data = _.pick(request.json, Crumb.get_public_properties()) crumb = Crumb() crumb.populate(**new_data) mapbox_params = { 'url': 'https://api.mapbox.com/geocoding/v5/mapbox.places', 'token': 'pk.eyJ1Ijoic2lkaGFydGEiLCJhIjoiY2ltczg2OW1yMDFpNHZsbTR6MWs5ZHlwbSJ9.T5h2oS8vItUFM9__uoRvaA', 'lng': crumb.lng, 'lat': crumb.lat } mapbox_url = '{url}/{lng},{lat}.json?access_token={token}&types=address'.format( **mapbox_params) response = json.load(urllib2.urlopen(mapbox_url)) addresses = response['features'] if addresses != None and len(addresses): crumb.place = addresses[0]['place_name'] crumb.put() return make_empty_ok_response()
def put(self): request.json['recaptcha_forms'] = util.dict_to_list(request.json['recaptcha_forms']) CONFIG_DB.populate(**request.json) CONFIG_DB.put() return make_empty_ok_response()
def delete(self, key): g.model_key.delete() return make_empty_ok_response()
def delete(self, key): """Deletes user""" g.model_key.delete() return make_empty_ok_response()
def post(self): """Resends email verification to user""" if g.user_db and not g.user_db.verified and g.user_db.active: task.verify_user_email_notification(g.user_db) return make_empty_ok_response()
def put(self): request.json['recaptcha_forms'] = util.dict_to_list( request.json['recaptcha_forms']) CONFIG_DB.populate(**request.json) CONFIG_DB.put() return make_empty_ok_response()
def post(self): """Generates mock data for development purposes""" if not DEVELOPMENT: abort(404) UserFactory.create_batch(50) return make_empty_ok_response()
def delete(self, key): """Deletes expense types""" g.model_key.delete() return make_empty_ok_response()