Example #1
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        errors = False
        if db.session.query(LearningTool).filter_by(name = form.short_name.data).first():
            form.short_name.errors.append(gettext('This name is already taken'))
            errors = True
        if db.session.query(LearningTool).filter_by(full_name = form.full_name.data).first():
            form.full_name.errors.append(gettext('This name is already taken'))
            errors = True
        if not errors:
            lt = LearningTool(name = form.short_name.data, full_name = form.full_name.data, url = form.url.data)
            shindig_credentials = ShindigCredentials(lt = lt, shindig_url = 'http://shindig2.epfl.ch')
            lt_user = LtUser(login = form.user_login.data, full_name = form.user_full_name.data, lt = lt, access_level = 'admin')
            lt_user.password = unicode(hashlib.new(ALGORITHM, form.user_password.data.encode('utf8')).hexdigest())
            for lab in db.session.query(Laboratory).filter_by(available = True).all():
                permission_to_lt = PermissionToLt(lt = lt, laboratory = lab, local_identifier = lab.default_local_identifier)
                db.session.add(permission_to_lt)
            db.session.add(lt)
            db.session.add(shindig_credentials)
            db.session.add(lt_user)
            db.session.commit()
            return redirect(url_for('login_ple', next = url_for('ple_admin.index')) )
            
    return render_template("opensocial/registration.html", form = form)
Example #2
0
 def reject_request(self):
     request_id = unicode(request.form['request_id'])
     req = self.session.query(RequestPermissionLT).filter_by(id = request_id).first()
     perm = PermissionToLt(lt = req.lt, laboratory = req.laboratory, configuration = '', local_identifier = req.local_identifier)
     self.session.add(perm)    
     self.session.delete(req)
     self.session.commit()
     return redirect(url_for('.index_view'))