Exemple #1
0
def create_user(user_type, user_dict):
    
    user_dict["password"] = hashlib.md5(user_dict["password"]).hexdigest()
    if user_type == "scholar":
        new_user = ScholarUser(**user_dict)
    else :
        new_user = DonorUser(**user_dict)
    Session.add(new_user)
    Session.commit()

    return new_user
Exemple #2
0
    def profile_update(self):
        user = ScholarUser.by_id(session['user']['id'])
        profile = Profile.by_user_id(session['user']['id'])
        
        if 'school' in request.params :
            school = School.by_name(request.params['school'])
            if not school:
                school = create_school(request.params['school'])
            profile.school = school
            profile.school_id = school.id
        if 'major' in request.params :
            profile.major = request.params['major']
        if 'gpa' in request.params : 
            profile.gpa = request.params['gpa']
        if 'hometown' in request.params :
            profile.hometown = request.params['hometown']
        #birthdate
        #race
        #religion
        #activities
        Session.add(profile)
        Session.commit()

        return "Profile updated."
Exemple #3
0
    def create(self):
        user = User.by_name(username=request.params['username'])
        if user:
            # The client tried to create a user that already exists
            abort(409, '409 Conflict',
                  headers=[('location', url('user', id=user.username))])  

        user_dict = {}
        for param in request.params:
            if param == "user_type":
                 user_type = request.params[param]
            else :
                user_dict[param] = request.params[param]
        
        new_user = create_user(user_type, user_dict)
        
        #new_user does not have a user id until after commit
        if user_type == "scholar":
            Session.add(Profile(new_user))
            Session.commit()
          
        session["user"] = {"id": new_user.id, "name": "%s %s" % (new_user.firstname, new_user.lastname)}
        session.save()
        return redirect("/"+user_type+"/")
Exemple #4
0
def create_school(name):
    school = School(name)
    Session.add(school)
    Session.commit()
    return school