Example #1
0
class Login(FlaskView):
  def __init__(self):
    self.userdb = Userdb()

  @route('/', methods=['GET', 'POST'])
  def login(self):
    vdict = copy.deepcopy(config.vdict)
    vdict['blog_title'] = 'ទំព័រ​ចុះឈ្មោះ'

    user = self.userdb.select(1)
    if not user:
      return redirect('/dashboard/signup/')

    if request.method == 'POST':
      email = request.form['femail']
      password = request.form['fpassword']

      if(self.userdb.check_user(email, password)):
        session['logged-in'] = email
        return redirect('/dashboard/')
        
    else:
      if 'logged-in' in session:
        return redirect('/dashboard/')
            
      return render_template('login.html', data=vdict)

  @route('/logout/')
  def logout(self):
    session.pop('logged-in', None)
    return redirect('/')
Example #2
0
 def __init__(self):
   self.lib = Lib()
   self.postdb = Postdb()
   self.categorydb = Categorydb()
   self.pagedb = Pagedb()
   self.bookdb = Bookdb()
   self.userdb = Userdb()
   self.settingdb = Settingdb()
Example #3
0
class User():
    def __init__(self):
        self.userdb = Userdb()

    def get_user(self, id):
        vdict = copy.deepcopy(config.vdict)
        vdict['user'] = self.userdb.select(1, id=id)

        return vdict
Example #4
0
class Login():
    def __init__(self):
        self.userdb = Userdb()

    def set_root(self):
        vlib = lib.Lib()
        vdatetime = vlib.get_timezone()
        date = datetime.strptime(vdatetime[0], "%d/%m/%Y")
        time = datetime.strptime(vdatetime[1], '%H:%M:%S')

        self.userdb.insert('root', '*****@*****.**', 'root', 'Admin', '',
                           date, time, 'root')

    def check_user(self):
        vdict = copy.deepcopy(config.vdict)
        vdict['site_title'] = 'ទំព័រ​ចុះឈ្មោះ'

        if (request.method == 'POST'):
            email = request.form['femail']
            password = request.form['fpassword']

            user = self.userdb.check_user(email, password)
            if (user):
                session['author-id'] = user[0]
                session['logged-in'] = user[1]
                return redirect('/dashboard/')

        else:
            if 'logged-in' in session:
                return redirect('/dashboard/')

            user = self.userdb.select(1)
            if not user:
                self.set_root()

        return render_template('login.html', data=vdict)
Example #5
0
class Movie():
    def __init__(self):
        self.lib = lib.Lib()
        self.userdb = Userdb()
        self.moviedb = Moviedb()

    def get_movie(self, id):
        vdict = copy.deepcopy(config.vdict)
        vdict['site_title'] = '​ភាពយន្ត​ទោល'

        vdict['movies'] = self.moviedb.select(vdict['random_max_movie'],
                                              random=id)
        vdict['thumbs'] = self.lib.get_thumbs(vdict['movies'], 5, type='movie')
        vdict['movie'] = self.moviedb.select(id=id)
        date = (vdict['movie'][6]).strftime('%d/%m/%Y')
        time = (vdict['movie'][7]).strftime('%H:%M:%S')
        vdict['datetime'] = (date, time)
        vdict['author'] = self.userdb.select(username=vdict['movie'][8])

        return render_template('movie.html', data=vdict)
Example #6
0
class Search():
  def __init__(self):
    self.lib = Lib()
    self.postdb = Postdb()
    self.categorydb = Categorydb()
    self.pagedb = Pagedb()
    self.bookdb = Bookdb()
    self.userdb = Userdb()
    self.settingdb = Settingdb()

  def get_post(self):
    vdict = copy.deepcopy(config.vdict)
    vdict['blog_title'] = 'ទំព័រ​ស្វែង​រក'

    if (request.method == "POST") and ('logged-in' in session):
      database = request.form['fsearch-option']
      fquery = request.form['fquery']

      if database == 'មេរៀន':
        vdict['search'] = self.postdb.search(fquery)
        vdict['type'] = 'post'
      elif database == 'ប្រភេទ​មេរៀន':
        vdict['search'] = self.categorydb.search(fquery)
        vdict['type'] = 'category'
      elif database == 'ទំព័រ​មាតិកា':
        vdict['search'] = self.pagedb.search(fquery)
        vdict['type'] = 'page'
      elif database == 'សៀវភៅ':
        vdict['search'] = self.bookdb.search(fquery)
        vdict['type'] = 'book'
      elif database == 'សមាជិក':
        vdict['search'] = self.userdb.search(fquery)
        vdict['type'] = 'user'

      return render_template('dashboard/search.html', data=vdict)

    elif 'logged-in' in session:
      return render_template('dashboard/search.html', data=vdict)
    else:
      return redirect('/login/')
Example #7
0
 def __init__(self):
   self.userdb = Userdb()
Example #8
0
 def __init__(self):
     self.userdb = Userdb()
     self.lib = lib.Lib()
Example #9
0
class User():
    def __init__(self):
        self.userdb = Userdb()
        self.lib = lib.Lib()

    def signup(self):
        vdict = copy.deepcopy(config.vdict)
        vdict['site_title'] = "ទំព័រ​អ្នក​ប្រើប្រាស់"
        vdict['datetime'] = self.lib.get_timezone()
        session['page'] = 0

        if request.method == "POST":
            username = request.form['fusername']
            content = request.form['fcontent']
            password = request.form['fpassword']
            role = request.form['frole']
            date = request.form['fdate']
            time = request.form['ftime']
            email = request.form['femail']
            edit_id = request.form['fedit-id']

            if not email:
                vdict['message'] = 'ចាំបាច់​ត្រូវ​មាន​ E-MAIL!'
                return render_template('dashboard/user.html', data=vdict)

            if (self.userdb.check_email(email)) and (not edit_id):
                vdict[
                    'message'] = 'E-MAIL នេះ​ត្រូវ​បាន​គេ​យក​ទៅ​ប្រើប្រាស់​ហើយ។'
                return render_template('dashboard/user.html', data=vdict)

            if 'logged-in' in session:
                author_id = session['author-id']
                author_role = self.userdb.check_author(author_id)
                author = author_role[1]
            else:
                author = 'root'

            try:
                date = datetime.datetime.strptime(date, "%d/%m/%Y")
            except ValueError:
                vdict['message'] = 'ទំរង់​កាលបរិច្ឆេទ​មិន​ត្រឹមត្រូវ!'
                return render_template('dashboard/user.html', data=vdict)

            try:
                time = datetime.datetime.strptime(time, "%H:%M:%S")
            except ValueError:
                vdict['message'] = 'ទំរង់​ពេល​វេលា​មិន​ត្រឹមត្រូវ!'
                return render_template('dashboard/user.html', data=vdict)

            if edit_id:
                if author_role[4] == 'Admin':
                    self.userdb.update(username, email, password, role,
                                       content, date, time, author, edit_id)
            else:
                if author_role[4] == 'Admin':
                    self.userdb.insert(username, email, password, role,
                                       content, date, time, author)

            vdict['users'] = self.userdb.select(vdict['dashboard_max_post'])
            vdict['thumbs'] = self.lib.get_thumbs(vdict['users'],
                                                  5,
                                                  type='user')
            return render_template('dashboard/user.html', data=vdict)

        elif 'logged-in' in session:
            vdict['users'] = self.userdb.select(vdict['dashboard_max_post'])
            vdict['thumbs'] = self.lib.get_thumbs(vdict['users'],
                                                  5,
                                                  type='user')
            return render_template('dashboard/user.html', data=vdict)
        else:
            return redirect('/login/')

    def edit(self, id):
        vdict = copy.deepcopy(config.vdict)
        vdict['blog_title'] = 'កែតំរូវ​អ្នក​ប្រើប្រាស់'
        vdict['edit-id'] = id

        if 'logged-in' in session:
            vdict['users'] = self.userdb.select(vdict['dashboard_max_post'])
            vdict['thumbs'] = self.lib.get_thumbs(vdict['users'],
                                                  5,
                                                  type='user')
            vdict['user'] = self.userdb.select(id=id)
            date = (vdict['user'][6]).strftime('%d/%m/%Y')
            time = (vdict['user'][7]).strftime('%H:%M:%S')
            vdict['datetime'] = (date, time)

            return render_template('dashboard/user.html', data=vdict)

        return redirect('/login/')

    def delete(self, id):
        author_id = session['author-id']
        author_role = self.userdb.check_author(author_id)
        if author_role[4] == 'Admin':
            self.userdb.delete(id)

        return redirect('/dashboard/user/signup/')

    def load(self):
        if 'logged-in' in session:
            vdict = copy.deepcopy(config.vdict)
            session['page'] += 1
            vdict['users'] = self.userdb.select(vdict['dashboard_max_post'],
                                                page=session['page'])
            vdict['thumbs'] = self.lib.get_thumbs(vdict['users'],
                                                  5,
                                                  type="user")

            new_list = []
            for user in vdict['users']:
                new_user = list(user)
                new_user[6] = user[6].strftime('%d/%m/%Y')
                new_user[7] = user[7].strftime('%H:%M:%S')
                new_list.append(new_user)

            vdict['users'] = new_list
            return vdict
        else:
            return render_template('login.html', data=vdict)