def _create(self): if config["app_conf"]["enable_new_users"] != "true": return self._message('User creation not enabled', 'error') if not req('username'): return self._message('Username missing', 'error') elif not req('password'): return self._message('Password missing', 'error') elif req('password_confirmation') != req('password'): return self._message('Passwords do not match', 'error') elif not req('email'): return self._message('Email missing', 'error') else: user_q = meta.Session.query(User) if user_q.filter(User.username == req('username')).count() > 0: return self._message('User already exists', 'error') os.makedirs(userdir(req('username'))) user = User() user.username = req('username') user.password = user.enc(req('password')) user.email = req('email') meta.Session.add(user) meta.Session.commit() return self._login()
def projects(self): projects = os.listdir(userdir(session['username'])) c.projects = [ MicroMock(url=unquote_plus(project), name=self._readname(project)) for project in projects ] return render('/user/projects.mako')
def __init__(self, source, revision=None): self.revision = revision and int(revision) self.project = None self.new = False self.zipfile = None self.config = None if isinstance(source, basestring): self.config = self._newconf(source) elif isinstance(source, ZipFile): self.zipfile = source try: conf = StringIO.StringIO(self.zipfile.read('sharetx.conf')) self.config = SafeConfigParser() self.config.readfp(conf) conf.close() except KeyError: self.config = self._newconf(str(uuid.uuid1())) self.new = True if not self.config: raise 'Configuration not found', source self.checkout_path = mkdtemp() self.branch_path = os.path.join(userdir(session['username']), self.config.get('sharetx', 'uri')) if self.new: if os.path.exists(self.branch_path): raise 'Project already exists', self.branch_path os.makedirs(self.branch_path) self.branch = BzrDir.create_branch_convenience(self.branch_path) else: self.branch = Branch.open(self.branch_path) if self.new: self.checkout() self.extract() conf = open(os.path.join(self.checkout_path, 'sharetx.conf'), 'wb') self.config.write(conf) conf.close() self.wt.add('sharetx.conf') elif self.zipfile: self.extract() else: self.checkout() self.project = CeltxRDFProject(self.checkout_path) # Re-read configuration and check version conf = os.path.join(self.checkout_path, 'sharetx.conf') self.config = SafeConfigParser() self.config.read(conf) version = self.config.get('sharetx', 'version') if version != '1': raise 'Not a valid version: %s' % version
def _readname(self, project): f = open(os.path.join(userdir(session['username']), project, 'name')) name = f.read() f.close() return name