def addUser(self, username, password, id=None):
     user = User(username=username,
                 password=self.pwhash(username, password))
     if id != None:
         user.id = id
     self.session.add(user)
     return user.json()
Esempio n. 2
0
def post_register():
    if 'user_id' not in session or \
    'name' not in request.form:
        return 'Invalied Data'
    name = request.form['name']
    id = session['user_id']

    user = User()
    user.id = id
    user.name = name

    DBSession.add(user)
    DBSession.commit()

    session['name'] = name
    return redirect(url_for('application'))
Esempio n. 3
0
    def create_user(self, spec_data=None, return_object=True):
        """
        Make a customer object, return the actual object with spec_data overriding values for further manipulation unless set to false.
        :param spec_data: A dictionary containing the data keyed on db model object attribute
        :param return_object: Whether to return the object or not, defaulting to True
        :return: a customer db model
        """
        u = User()

        if spec_data is None:
            spec_data = {}
        sqlobj_from_dict(u, spec_data)

        if u.id is None:
            u.id = self.session.query(func.nextval('users_id_seq')).scalar()
        if u.username is None:
            u.username = '******' % u.id
        if u.email is None:
            u.email = '*****@*****.**' % u.id
        if u.salt is None:
            u.salt = 'generated_salt%d' % u.id
        if u.password is None:
            u.password = '******' % u.id

        if isinstance(u.salt, basestring):
            s = hashlib.sha512()
            s.update(u.salt.encode('utf-8'))
            u.salt = s.digest()
        if isinstance(u.password, basestring):
            m = hashlib.sha512()
            m.update(u.password.encode('utf-8'))
            m.update(u.salt)
            u.password = m.digest()

        self.session.add(u)
        self.session.flush()
        self.session.refresh(u)
        if return_object:
            return u
        return u.id