def post(self): try: email = self.request.get('email') hkey = self.request.get('hkey') tenant_id = tenant.get_tenant_id(email) namespace_manager.set_namespace(tenant_id) if User.get_by_key_name(email): raise AppError(u'このメールアドレスは、既に登録されています。') if self.request.get('button') == 'Send Activate Key': key = ActivateKey.make(email) self.send_activate_key(email, key[:12]) hkey = key[12:] self.render_template('signup.html', {'email': email, 'hkey': hkey}) return else: key = self.request.get('key1') + self.request.get('key2') + self.request.get('key3') + self.request.get('hkey') if not ActivateKey.validate(email, key): raise AppError(u'不正な Activate Key です。') password = self.request.get('password') if not string.strip(password): raise AppError(u'パスワードが未入力です。') user = User(key_name=email, email=email, password=hashlib.md5(email + password).hexdigest()) user.put() self.redirect('/') except AppError, e: self.render_template('signup.html', {'error_msg': e.message, 'email': email, 'hkey': hkey})
def get_tenant_id(email): email_part = email.split('@') if not mail.is_email_valid(email): raise (u'正しくないメールアドレスです。') if not email_part[1] in sysconf.ALLOWED_DOMAINS.keys(): raise AppError(u'認められていないメールアドレスです。') return sysconf.ALLOWED_DOMAINS[email_part[1]]
def get(self): try: book_id = self.request.get('id') if book_id: user = basic_auth.get_current_user() ubook = UsersBook.get_by_key_name(book_id + ':' + user.email) if not ubook: raise AppError(u'指定された本の登録はありません。') ubook.delete() self.redirect('/list_book') except AppError, e: self.render_template('error.html', {'error_msg': e.message})
def get(self): book_id = self.request.get('id') try: book = Book.get_by_key_name(book_id) if not book: raise AppError(u'指定された本は見つかりませんでした。') users = UsersBook.get_by_book_id(book_id) self.render_template('show_book.html', { 'book': book, 'users': users }) except AppError, e: self.render_template('error.html', {'error_msg': e.message})
def post(self): try: keyword = self.request.get('q') if not string.strip(keyword): raise AppError(u'キーワードが入力されていません。') books = Book.search(keyword) self.render_template('add_book.html', { 'keyword': keyword, 'books': books }) except AppError, e: self.render_template('add_book.html', {'error_msg': e.message})
def get(self): try: book_id = self.request.get('id') if book_id: user = basic_auth.get_current_user() book = Book.get_by_key_name(book_id) if not book: raise AppError(u'指定された本は見つかりませんでした。') ubook = UsersBook(key_name=book_id + ':' + user.email, user=user, book_id=book_id) ubook.put() self.redirect('/list_book') else: self.render_template('add_book.html') except AppError, e: self.render_template('error.html', {'error_msg': e.message})
def get(self): try: user = basic_auth.get_current_user() email = self.request.get('email') if email: if user.email == email: self.redirect('/list_book') return else: friend = User.get_by_key_name(email) if not friend: raise AppError(u'指定されたメールアドレスに該当するユーザはいません。') ubooks = UsersBook.get_by_user(friend) else: friend = None ubooks = UsersBook.get_by_user(user) books = [Book.get_by_key_name(ubook.book_id) for ubook in ubooks] self.render_template('list_book.html', { 'books': books, 'friend': friend }) except AppError, e: self.render_template('list_book.html', {'error_msg': e.message})