def post(self): """Registers a new user. If received data is valid, creates a new ``User``, stores it into the database and sets a cookie named ``user_id``. ``first_name``, ``last_name``, ``email`` and ``password`` key-value pairs are required. { "first_name":"Jon", "last_name":"Snow", "email": "*****@*****.**", "password":"******", "region_id":1 } """ args = self.request.arguments new_user = store_new_user( self.sess, User(first_name=args['first_name'], last_name=define_values(args, 'last_name'), email=args['email'], password=hash_password(args['password']), region_id=define_values(args, 'region_id'))) if not new_user: return self.send_error(400, message='Email already in use.') complete_auth(self, new_user)
def create_gp_user(user_profile): return User(first_name=user_profile['first_name'], last_name=define_values(user_profile, 'last_name'), email=user_profile['email'], region_id=define_values(user_profile, 'region_id'), google_id=user_profile['google_id'], password=hash_password("googlepassword"))
def create_fb_user(user_profile): return User(first_name=user_profile['first_name'], last_name=define_values(user_profile, 'last_name'), email=user_profile['email'], region_id=define_values(user_profile, 'region_id'), facebook_id=user_profile['facebook_id'], password=hash_password("facebookpassword"))
def post(self): """Logs in a user. Sets a cookie ``user_id`` and writes user's ``first_name`` and ``last_name`` to the client (so it can display them in the navbar). ``email`` and ``password`` key-value pairs are required in request JSON payload. If user authentication fails, a client gets 400 response status code and a message *"Invalid email/password."*. { "email": "*****@*****.**", "password":"******" } """ args = self.request.arguments user = get_user_with_email(self, args['email']) if user and user.password == hash_password(args['password']): complete_auth(self, user) else: self.send_error(400, message='Invalid email/password.')
def migrate_user(self): """Migrate all users in new db. """ # add admin_user admin = User(id=1, first_name='admin', last_name='admin_lastname', email='*****@*****.**', password=hash_password('admin_pass'), region_id=1) self.session.add(admin) users = self.mysql_db.Users.all() for user in users: user_data = User(id=user.Id, first_name=user.Name, last_name=user.Surname, email=user.Email, password=user.Password, region_id=1) self.session.add(user_data) self.session.commit() self._migrate_user_roles(users) self._fix_id(obj_res=User)