Ejemplo n.º 1
0
def login():
    try:
        if session['user_id']:
            return redirect("/index")
    except:
        pass
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(users_db.get_connection())
        true_pass = user_model.password_check(user_name)
        exists = user_model.exists(user_name, true_pass)
        if check_password_hash(true_pass, password) and exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
            session['block'] = exists[2]
            return redirect("/index")
        else:
            all_data = user_model.get_all()
            for x in all_data:
                if user_name == x[1]:
                    return render_template('login.html',
                                           title='Авторизация',
                                           form=form,
                                           alert='Неправильный пароль')
            return render_template('login.html',
                                   title='Авторизация',
                                   form=form,
                                   alert='Такой пользователь не существует')
    return render_template('login.html',
                           title='Авторизация',
                           form=form,
                           alert='')
Ejemplo n.º 2
0
def unblock(user_id):
    if 'username' not in session:
        return redirect('/ban')
    if session['username'] != 'admin':
        return redirect('/index')
    user = UsersModel(users_db.get_connection())
    user.unblock(user_id)
    return redirect('/index')
Ejemplo n.º 3
0
	def change_order_status(self,orderNum,new_status):
		"""修改订单状态   default0   has_pay:1  not_pay:2    new_status(true,false) """
		order_info = self.find_data(['pay_status','uid','credits'],get_some=False,orderNum=orderNum)
		order_status = order_info['pay_status']
		if not order_status: #只有订单状态没有发生任何改变才会修改订单状态
		    change_into = 2 if new_status == 'false' else 1
		    self.update_db({'pay_status':change_into},orderNum=orderNum)
		    if new_status == 'false':  #如果回调的数据是失败的,那么返回用户积分
		        UsersModel.get_instance().change_user_point(order_info['uid'],order_info['credits']) #返还用户积分(如果失败)
		return True
Ejemplo n.º 4
0
def sign_in():
    form = SigninForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(u_db.get_connection())
        exists = user_model.exists(user_name, password)
        if exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect('/home')
    return render_template('sign_in.html', title='Авторизация', form=form)
Ejemplo n.º 5
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(users_db.get_connection())
        true_pass = user_model.password_check(user_name)
        exists = user_model.exists(user_name, true_pass)
        if check_password_hash(true_pass, password) and exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('login.html', title='Sign in', form=form)
Ejemplo n.º 6
0
def login():
    form = LoginForm()
    user_name = form.username.data
    password = form.password.data
    user_model = UsersModel(db.get_connection())
    exists = user_model.exists(user_name, password)
    if form.validate_on_submit():

        if (exists[0]):
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect("/index")
    return render_template('login.html', form=form, message=user_model.exists(user_name, password)[1])
Ejemplo n.º 7
0
 def change_order_status(self, orderNum, new_status):
     """修改订单状态   default0   has_pay:1  not_pay:2    new_status(true,false) """
     order_info = self.find_data(['pay_status', 'uid', 'credits'],
                                 get_some=False,
                                 orderNum=orderNum)
     order_status = order_info['pay_status']
     if not order_status:  #只有订单状态没有发生任何改变才会修改订单状态
         change_into = 2 if new_status == 'false' else 1
         self.update_db({'pay_status': change_into}, orderNum=orderNum)
         if new_status == 'false':  #如果回调的数据是失败的,那么返回用户积分
             UsersModel.get_instance().change_user_point(
                 order_info['uid'], order_info['credits'])  #返还用户积分(如果失败)
     return True
Ejemplo n.º 8
0
def register():
    form = RegisterForm()
    if request.method == 'GET':
        return render_template('register.html', form=form)
    elif request.method == 'POST':
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        user_model.insert(user_name, password)
        exists = user_model.exists(user_name, password)
        if (exists[0]):
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect("/index")
Ejemplo n.º 9
0
 def get_interact(self, comm_id, page):
     """直接根据团队id获取这个互动  这块还是先查到这条数据的id 再查找多条数据"""
     # return [rows for rows in self.m_c.find({search_key:int(id)})]
     page = int(page)
     per_page = 10
     interact_info = self.m_c.find({
         'comm_id': comm_id
     }, {
         'content': 1,
         'time': 1,
         '_id': 0,
         'uid': 1
     }).skip(per_page * page).limit(per_page).sort([('time', -1)])
     interact_list = []
     current_time = PublicFunc.get_current_stamp()
     index = page * per_page
     for info in interact_info:
         index += 1
         info['time'] = PublicFunc.time_format_span(info['time'],
                                                    current_time)
         info['index'] = index
         if not info['uid']:
             info['avatar'] = 'http://101.200.214.68/Uploads/head.png'
             info['nickname'] = '游客'
         else:
             user_info = UsersModel.get_instance().get_import_user_info(
                 info['uid'], ['avatar', 'username'])
             info['avatar'] = user_info['avatar']
             info['nickname'] = user_info['username']
         del info['uid']
         interact_list.append(info)
     return interact_list
Ejemplo n.º 10
0
 def get_community_rank(self, comm_id, page):
     """
 	function: 获取圈子排名
 	author: yinshuai 
 	input param:
 	        comm_id 跑团主键id
 	        page 分页
 	return: 
 	        跑团用户排名数据
 	"""
     page = int(page)
     per_page = 10
     # comm_run_list = self.m_c.find({"_id":ObjectId(comm_id)},{'uid':1,'distance':1,'_id':0}).sort([('distance',-1)]).skip(page*per_page).limit(per_page)
     # comm_info = self.m_c.find({"_id":ObjectId(comm_id)},{'_id':0,'gid':0,'comm_name':0,'comm_member':{"$slice":[0,3]}})
     # comm_info = self.m_c.find_one({"_id":ObjectId(comm_id)},{"$or":[{'comm_member':1},{'comm_member':{"$slice":[0,3]}}]})
     comm_info = self.m_c.find_one({"_id": ObjectId(comm_id)}, {
         'comm_member': {
             "$slice": [per_page * page, per_page]
         },
         'gid': 1
     })
     comm_member = comm_info['comm_member']
     for member_info in comm_member:
         user_info = UsersModel.get_instance().get_import_user_info(
             member_info['uid'], ['avatar', 'nickname'])
         member_info['avatar'] = user_info['avatar']
         if not 'distance' in member_info: member_info['distance'] = 0
         member_info['nickname'] = user_info['nickname'] if user_info[
             'nickname'] else '小跑男'
     return comm_member
Ejemplo n.º 11
0
 def __get_group_user_info_via_uid_list(self, uid_list):
     group_user_info_list = []
     for uid in uid_list:
         group_user_info_list.append(
             UsersModel.get_instance().get_import_user_info(
                 uid, ['avatar', 'point', 'nickname', 'uid']))
     return group_user_info_list
Ejemplo n.º 12
0
def admin_only():
    if 'username' not in session:
        return redirect('/login')
    news = NewsModel(news_db.get_connection()).get_all()
    news.sort(key=lambda x: x[3])
    user_model = UsersModel(users_db.get_connection())
    usernames = {}
    for item in news:
        data = user_model.get(item[4])
        if item[4] not in usernames:
            usernames.update(
                {item[4]: [str(data[2] + ' ' + data[3]), data[1]]})
    return render_template('index.html',
                           username=session['username'],
                           news=news,
                           users=usernames)
Ejemplo n.º 13
0
def reg():
    form = RegistForm()
    if form.validate_on_submit():
        ind = ''
        f = open('users', encoding="utf-8", mode='r+')
        ff = open('admins', encoding="utf-8", mode='r+')
        datauser = f.read()
        dataadmin = ff.read()
        user_name = form.username.data
        password = form.password.data
        repeat = form.repeat.data
        mail = form.mail.data
        code = form.user_admin.data
        user_model = UsersModel(db.get_connection())
        user_model.insert(user_name, password)
        exists = user_model.exists(user_name, password)
        if str(code) == 'sell':
            ind = 'admin'
        else:
            ind = 'user'
        if password != repeat:
            return redirect('/register')
        if ind == 'admin':
            if user_name not in dataadmin:
                ff.write('\n')
                ff.write(user_name)
                ff.write(':')
                ff.write(password)
                ff.write(':')
                ff.write(mail)
            else:
                return redirect('/register')
        else:
            if user_name not in datauser:
                f.write('\n')
                f.write(user_name)
                f.write(':')
                f.write(password)
                f.write(':')
                f.write(mail)
            else:
                return redirect('/register')
        if exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('regist.html', title='Регистрация', form=form)
Ejemplo n.º 14
0
def reg():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        surname = form.surname.data
        password = form.password.data
        confirm = form.confirm.data
        password_hash = generate_password_hash(password)
        user_model = UsersModel(users_db.get_connection())

        all_data = user_model.get_all()
        for x in all_data:
            if username == x[1]:
                return render_template(
                    'reg.html',
                    title='Регистрация',
                    form=form,
                    alert='Такой пользователь уже зареестрирован')

        exists = user_model.exists(username, password_hash)
        if not exists[0] and password == confirm:
            user_model.insert(username, name, surname, password_hash)
            exists = user_model.exists(username, password_hash)
            session['username'] = username
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('reg.html',
                           title='Регистрация',
                           form=form,
                           alert='')
Ejemplo n.º 15
0
 def __get_group_user_info_via_uid_list(self,uid_list):
 	info_return = [] 
 	for uid in uid_list:
         user_info = UsersModel.get_instance().get_import_user_info(uid,['nickname','point','uid','avatar'])
 		# info_return.append(UsersModel.get_instance().get_import_user_info(uid,['username','point','uid','avatar'])) 
         user_info['username'] = user_info['nickname'] if user_info['nickname'] else options.default_nick_name
         user_info['uid'] = uid
         info_return.append(user_info)
 	return info_return
Ejemplo n.º 16
0
def admin_only():
    if 'username' not in session:
        return redirect('/ban')
    if session['username'] != 'admin':
        return redirect('/index')
    news = UsersModel(users_db.get_connection()).get_all()
    return render_template('users.html',
                           username=session['username'],
                           news=news)
Ejemplo n.º 17
0
def login():
    global ind
    form = LoginForm()
    if form.validate_on_submit():
        f = open('admins', encoding="utf-8", mode='r+')
        data = f.read().split('\n')
        ff = open('users', encoding="utf-8", mode='r+')
        data1 = ff.read().split('\n')
        logins = {}
        login = []
        for i in data:
            i = i.split(':')
            logins[str(i[0])] = str(i[1])
            login.append(str(i[0]))
            user_name = str(form.username.data)
            password = str(form.password.data)
            if user_name in login:
                if str(logins[user_name]) == str(password):
                    user_model = UsersModel(db.get_connection())
                    user_model.insert(user_name, password)
                    exists = user_model.exists(user_name, password)
                    if (exists[0]):
                        session['username'] = user_name
                        session['user_id'] = exists[1]
                return redirect("/admin")
            else:
                for i in data1:
                    i = i.split(':')
                    logins[i[0]] = i[1]
                    login.append(i[0])
                    user_name = form.username.data
                    password = form.password.data
                    if user_name in login:
                        if str(logins[user_name]) == str(password):
                            user_model = UsersModel(db.get_connection())
                            user_model.insert(user_name, password)
                            exists = user_model.exists(user_name, password)
                            if (exists[0]):
                                session['username'] = user_name
                                session['user_id'] = exists[1]
                        return redirect("/user")
    return render_template('login.html', title='Авторизация', form=form)
Ejemplo n.º 18
0
def index():
    if 'username' not in session:
        return redirect('/ban')
    news = NewsModel(news_db.get_connection()).get_all(session['user_id'])
    news.sort(key=lambda x: x[3])
    news.reverse()
    user_model = UsersModel(users_db.get_connection())
    usernames = {}
    for item in news:
        data = user_model.get(item[4])
        if item[4] not in usernames:
            usernames.update(
                {item[4]: [str(data[2] + ' ' + data[3]), data[1]]})

    return render_template('index.html',
                           title='a',
                           username=session['username'],
                           cur_user_id=session['user_id'],
                           news=news,
                           users=usernames)
Ejemplo n.º 19
0
 def __get_group_user_info_via_uid_list(self, uid_list):
     info_return = []
     for uid in uid_list:
         user_info = UsersModel.get_instance().get_import_user_info(
             uid, ['nickname', 'point', 'uid', 'avatar'])
         # info_return.append(UsersModel.get_instance().get_import_user_info(uid,['username','point','uid','avatar']))
         user_info['username'] = user_info['nickname'] if user_info[
             'nickname'] else options.default_nick_name
         user_info['uid'] = uid
         info_return.append(user_info)
     return info_return
Ejemplo n.º 20
0
	def get_reward_list(self,page):
		page = int(page)
		per_page = 30
		reward_list = self.find_data(['description','timestamp','id','uid'],get_some=(page*5,per_page)) #aaaaaaa
		current_time = PublicFunc.get_current_stamp()
		for index,reward in enumerate(reward_list):
			user_info = UsersModel.get_instance().get_import_user_info(reward['uid'],['avatar','nickname'])
			reward_list[index]['nickname'] = '小跑男' if not user_info['nickname']  else user_info['nickname']  
			reward_list[index]['avatar'] = user_info['avatar']
			reward_list[index]['time'] = PublicFunc.time_format_span(str(reward['timestamp'])[:-3],current_time) 
			del reward_list[index]['timestamp']
		return reward_list
Ejemplo n.º 21
0
def user_data(user_id):
    if 'username' not in session:
        return redirect('/ban')
    user_model = UsersModel(users_db.get_connection())
    data = user_model.get(user_id)
    news = NewsModel(news_db.get_connection()).get_all(user_id)
    path = data[6]
    if session['user_id'] == user_id:
        my_page = True
    else:
        my_page = False
    name_surname = data[2] + ' ' + data[3]
    return render_template('user_data.html',
                           title=name_surname,
                           my_page=my_page,
                           cur_user_id=session['user_id'],
                           path=path,
                           name=data[2],
                           surname=data[3],
                           status=data[4],
                           news=news)
Ejemplo n.º 22
0
def news_data(news_id):
    if 'username' not in session:
        return redirect('/ban')
    form = CommentForm()
    if form.validate_on_submit():
        content = form.content.data
        cm = CommentsModel(comments_db.get_connection())
        author_data = UsersModel(users_db.get_connection()).get(
            session['user_id'])
        username = author_data[2] + ' ' + author_data[3]
        cm.insert(session['user_id'], news_id, content, username)
        return redirect("/news/" + str(news_id))
    news = NewsModel(news_db.get_connection()).get(news_id)
    author_data = UsersModel(users_db.get_connection()).get(news[4])
    username = author_data[2] + ' ' + author_data[3]
    cm = CommentsModel(comments_db.get_connection()).get_all(news[0])
    cm.reverse()
    return render_template('news_data.html',
                           title=news[1],
                           author=username,
                           cur_user_id=session['user_id'],
                           news=news,
                           cm=cm,
                           form=form)
Ejemplo n.º 23
0
def personal():
    user_model = UsersModel(u_db.get_connection())
    row = list(user_model.get(session['user_id']))
    snippet = {
        'Логин': '',
        'Пароль': '',
        'Номер карты': '',
        'Дата истечения': '',
        'Имя': '',
        'Трехзначный код': '',
        'Баланс': ''
    }
    i = 1
    for el in snippet:
        if i == 4:
            snippet[el] = str(row[i]) + '/' + str(row[i + 1])
            i += 2
        else:
            snippet[el] = str(row[i])
            i += 1
    tuple_s = []
    for el in snippet:
        tuple_s.append((el, snippet[el]))
    return render_template('personal.html', lists=tuple_s)
Ejemplo n.º 24
0
 def get_reward_list(self, page):
     page = int(page)
     per_page = 30
     reward_list = self.find_data(['description', 'timestamp', 'id', 'uid'],
                                  get_some=(page * 5, per_page))  #aaaaaaa
     current_time = PublicFunc.get_current_stamp()
     for index, reward in enumerate(reward_list):
         user_info = UsersModel.get_instance().get_import_user_info(
             reward['uid'], ['avatar', 'nickname'])
         reward_list[index]['nickname'] = '小跑男' if not user_info[
             'nickname'] else user_info['nickname']
         reward_list[index]['avatar'] = user_info['avatar']
         reward_list[index]['time'] = PublicFunc.time_format_span(
             str(reward['timestamp'])[:-3], current_time)
         del reward_list[index]['timestamp']
     return reward_list
Ejemplo n.º 25
0
 def get_recent_run_man_single(self,eid):
 	"""获取最近运动的用户 针对于仅仅有一个项目的"""
 	recent_man_list = []
 	show_num = 6 
 	jump = 0 
 	while len(recent_man_list) < show_num:
 		user_run_list = self.find_data(['uid','step_count'],get_some=(jump,show_num),order=' id desc ',status=0)
 		if not user_run_list: break
 		jump += show_num
 		for user_run in user_run_list:
 			user_info = UsersModel.get_instance().get_import_user_info(user_run['uid'],['avatar','username','nickname'])
 			user_run['nickname'] = user_info['nickname'] if user_info['nickname'] else '小跑男'
 			user_run['avatar'] = user_info['avatar']
 			recent_man_list.append(user_run)
 			if len(recent_man_list) == show_num: break
 		if len(recent_man_list) == show_num: break
 	return recent_man_list
Ejemplo n.º 26
0
	def get_note_list(self,code,page):
		"""
		function:获取帖子列表
             置顶的排在前面,第二顺序为发布时间,时间越晚越靠前
		"""
		note_per_page = int(options.note_per_page)
		page = int(page)
		if code:
			note_list = list(self.m_c.find({'status':0,'code':code},{'content':0,'status':0}).sort([('up',-1),('time',-1)]).skip(note_per_page*page).limit(note_per_page))
		else:
			note_list = list(self.m_c.find({'status':0},{'content':0,'status':0}).sort([('up',-1),('time',-1)]).skip(note_per_page*page).limit(note_per_page))
		current_time = PublicFunc.get_current_stamp()
		for note in note_list:
			note['time'] = PublicFunc.time_format_span(note['time'],current_time)
			user_info = UsersModel.get_instance().get_import_user_info(note['uid'],['nickname','avatar'])
			note['avatar'] = user_info['avatar'] 
			note['nickname'] = user_info['nickname'] if user_info['nickname'] else options.default_nick_name
			note['is_up'] = 1 if int(note['up']) else 0 
			del note['up']
			note['note_id'] = str(note['_id'])
			del note['_id']
		return note_list
Ejemplo n.º 27
0
 def get_community_rank(self,comm_id,page):
 	"""
 	function: 获取圈子排名
 	author: yinshuai 
 	input param:
 	        comm_id 跑团主键id
 	        page 分页
 	return: 
 	        跑团用户排名数据
 	"""
 	page = int(page)
 	per_page = 10
 	# comm_run_list = self.m_c.find({"_id":ObjectId(comm_id)},{'uid':1,'distance':1,'_id':0}).sort([('distance',-1)]).skip(page*per_page).limit(per_page)
 	# comm_info = self.m_c.find({"_id":ObjectId(comm_id)},{'_id':0,'gid':0,'comm_name':0,'comm_member':{"$slice":[0,3]}})
 	# comm_info = self.m_c.find_one({"_id":ObjectId(comm_id)},{"$or":[{'comm_member':1},{'comm_member':{"$slice":[0,3]}}]})
 	comm_info = self.m_c.find_one({"_id":ObjectId(comm_id)},{'comm_member':{"$slice":[per_page*page,per_page]},'gid':1})
     comm_member = comm_info['comm_member']
 	for member_info in comm_member:
 		user_info = UsersModel.get_instance().get_import_user_info(member_info['uid'],['avatar','nickname'])
 		member_info['avatar'] = user_info['avatar']
     	if not 'distance' in member_info: member_info['distance'] = 0
 		member_info['nickname'] = user_info['nickname'] if user_info['nickname'] else '小跑男'
 	return comm_member
Ejemplo n.º 28
0
 def get_interact(self,comm_id,page):
 	"""直接根据团队id获取这个互动  这块还是先查到这条数据的id 再查找多条数据"""
 	# return [rows for rows in self.m_c.find({search_key:int(id)})]
 	page = int(page)
 	per_page = 10 
 	interact_info = self.m_c.find({'comm_id':comm_id},{'content':1,'time':1,'_id':0,'uid':1}).skip(per_page*page).limit(per_page).sort([('time',-1)])
 	interact_list = [] 
 	current_time = PublicFunc.get_current_stamp()
 	index = page * per_page
 	for info in interact_info:
 		index += 1 
 		info['time'] = PublicFunc.time_format_span(info['time'],current_time)
 		info['index'] = index
 		if not info['uid']:
 			info['avatar'] = 'http://101.200.214.68/Uploads/head.png'
 			info['nickname'] = '游客'
 		else:
 			user_info = UsersModel.get_instance().get_import_user_info(info['uid'],['avatar','username'])
 			info['avatar'] = user_info['avatar']
 			info['nickname'] = user_info['username']
 		del info['uid']
 		interact_list.append(info)
 	return interact_list
Ejemplo n.º 29
0
def api_auth():
    if not request.json:
        return json.dumps({'error': 'Empty request'})
    elif not all(key in request.json for key in ['pass', 'login']):
        return json.dumps({'error': 'Bad request'})

    password = request.json['pass']
    user_name = request.json['login']

    user_model = UsersModel(users_db.get_connection())
    true_pass = user_model.password_check(user_name)
    exists = user_model.exists(user_name, true_pass)
    if check_password_hash(true_pass, password) and exists[0]:
        token = generate_password_hash(str(password) + str(user_name))
        user_model.add_token(token, exists[1])
        return json.dumps({'token': token})
    else:
        return json.dumps({'error': 'Incorrect info'})
Ejemplo n.º 30
0
def user_edit():
    if 'username' not in session:
        return redirect('/ban')
    form = EditForm()
    if form.validate_on_submit():
        url = form.photo.data
        status = form.status.data
        nm = UsersModel(users_db.get_connection())
        nm.update_status(status, session['user_id'])
        nm.update_photo(url, session['user_id'])
        my_page = '/' + str(session['user_id'])
        return redirect(my_page)
    return render_template('edit.html',
                           title='Редактирование',
                           form=form,
                           my_page=False,
                           cur_user_id=session['user_id'],
                           username=session['username'])
Ejemplo n.º 31
0
def reg():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        surname = form.surname.data
        password = form.password.data
        confirm = form.confirm.data
        password_hash = generate_password_hash(password)
        user_model = UsersModel(users_db.get_connection())
        exists = user_model.exists(username, password_hash)
        if not exists[0] and password == confirm:
            user_model.insert(username, name, surname, password_hash)
            exists = user_model.exists(username, password_hash)
            session['username'] = username
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('reg.html', title='Sign up', form=form)
Ejemplo n.º 32
0
def sign_up():
    if request.method == 'POST':
        user_name = request.form['login']
        password = request.form['password']
        card_number = request.form['card_number']
        expiry_m = request.form['expiry_m']
        expiry_y = request.form['expiry_y']
        name = request.form['name']
        safe_number = request.form['ccv']
        money = request.form['money']
        user_model = UsersModel(u_db.get_connection())
        if not user_model.exists(user_name)[0] and card_check(card_number) and check_data(expiry_m, expiry_y) and\
            name_check(name) and cvv_check(safe_number) and check_money(money):
            if not user_model.exist_card_number(card_number)[0]:
                user_model.insert(user_name, password, card_number, expiry_m,
                                  expiry_y, name, safe_number, money)
                session['username'] = user_name
                session['user_id'] = user_model.exists(user_name, password)[1]
                return redirect('/home')
        else:
            return render_template('sign_up2.html', title='Регистрация')
    return render_template('sign_up.html', title='Регистрация')
Ejemplo n.º 33
0
def register():
    form = RegisterForm()
    if request.method == 'GET':
        return render_template('register.html', form=form, message="")
    elif request.method == 'POST':
        if form.password.data != form.trypassword.data:
            return render_template('register.html',
                                   form=form,
                                   message="Пароли не совпадают")
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        if user_model.get_by_name(user_name) is None:
            user_model.insert(user_name, password)
            exists = user_model.exists(user_name, password)
            return redirect("/login")
        else:
            return render_template(
                'register.html',
                form=form,
                message="Такой пользователь уже есть. Исправьте данные")
        """
Ejemplo n.º 34
0
    def __get_group_user_info_via_uid_list(self,uid_list):
		group_user_info_list = []
		for uid in uid_list:
			group_user_info_list.append(UsersModel.get_instance().get_import_user_info(uid,['avatar','point','nickname','uid']))
		return group_user_info_list
Ejemplo n.º 35
0
 def __init__(self):
     MongoBase.__init__(self)
     self.m_c = self.mongo_db.follow
     self.following_per_page = int(options.following_per_page)
     self.usersmodel = UsersModel()
Ejemplo n.º 36
0
    def __init__(self):
	    DbBase.__init__(self)
	    self.usersmodel = UsersModel.get_instance()
Ejemplo n.º 37
0
from regform import RegForm
from commentform import CommentForm
from usersmodel import UsersModel
from newsmodel import NewsModel
from commentsmodel import CommentsModel
from editform import EditForm
from shutil import copy
from db import DB
import datetime

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'
users_db = DB('users.db')
news_db = DB('news.db')
comments_db = DB('comments.db')
users_init = UsersModel(users_db.get_connection())
users_init.init_table()
news_init = NewsModel(news_db.get_connection())
news_init.init_table()
comments_init = CommentsModel(comments_db.get_connection())
comments_init.init_table()


@app.route('/')
@app.route('/index')
def index():
    if 'username' not in session:
        return redirect('/ban')
    news = NewsModel(news_db.get_connection()).get_all(session['user_id'])
    news.sort(key=lambda x: x[3])
    news.reverse()