def _get_user_from_db(self, row) -> User: user = User(db_id=row[0], telegram_id=row[1], balance=row[2], is_follower=row[3], invited_by=row[4]) return user
def register(): now = datetime.now() app.logger.info( str(now.strftime("%H:%M %Y-%m-%d")) + ' ' + __file__ + ' ' + inspect.stack()[0][3]) if current_user.is_authenticated and current_user.admin: form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() user = User.query.filter_by(email=form.email.data).first() conn = sl.connect('logs.db') conn.execute("INSERT INTO ACTIVITY VALUES (?,?,?,?)", (now.strftime("%H:%M %Y-%m-%d"), current_user.username, "Created: " + user.username+ " ("+current_user.email+")" + " User in the system."\ , "Register Page.")) conn.commit() flash('Your account has been created!', 'success') sendMail.user_register(user) return redirect(url_for('login')) return render_template(r'register.html', title='Register', form=form) else: flash('you do not have permission to register new users!', 'danger') return redirect(url_for('account'))
def regist(self, username, password, email, role='ordinary'): """ 注册用户,从首页注册的都是普通用户,后台注册可以指定是什么用户 :return: """ # self.session.add(User(username=username, password=password, email=email)) # self.session.add(Role(name='ordinary')) # self.session.commit() try: role_list = [] user = User(username=username, password=password, email=email, create_date=get_datetime()) role_obj = self.session.query(Role).filter(Role.name == role).first() print(role_obj.id) if role_obj is not None: role = role_obj role_list.append(role) else: role = Role(name='ordinary') self.session.add(role) self.session.commit() user.roles = role_list self.session.add(user) self.session.commit() return True except IntegrityError as e: return False
def send_welcome(message): user = User(telegram_id=message.chat.id, username=message.chat.username) if user.not_in_base(): user.add_user_in_db() message = user.get_welcome_message() bot.send_message(chat_id=user.user_id, text=message, reply_markup=START_TEST_BUTTON)
def get_user_from_db(user: tuple) -> User: user = User(db_id=user[0], telegram_id=user[1], balance=user[2], status=user[3], is_follower=user[4], invited_by=user[5], quantity_of_trades=user[6], earned_from_partnership=user[7]) return user
def get_user_by_telegram_id(self, telegram_id: int) -> User or None: rows = self._select_all() for row in rows: user = User(db_id=row[0], telegram_id=row[1], balance=row[2], is_follower=row[3], invited_by=row[4]) if int(user.telegram_id) == int(telegram_id): return user return None
def add_new_user_to_db(self, user_id, follow_status=0, invited_by=0): user = User(telegram_id=user_id, is_follower=follow_status, invited_by=invited_by) telegram_ids_from_db = self.select_column_from_db( 'telegram_id', 'users') if telegram_ids_from_db is None or self.get_user_by_telegram_id( user.telegram_id) is None: self.insert_user_in_db(user) return user else: user = self.get_user_by_telegram_id(user.telegram_id) return user
def seed_data(): user = User.query.all() # show all user(s) try: if not user: create_admin = User() create_admin.username = '******' create_admin.set_password('gibran') create_admin.email = '*****@*****.**' create_admin.nama_lengkap = 'Gibran Abdillah' create_admin.is_admin = True db.session.add(create_admin) db.session.commit() print('Done create user') except Exception as e: print('Cant create user', e)
def register(): if(current_user.is_authenticated): return redirect(url_for('main.home')) form = RegistrationForm() if(form.validate_on_submit()): hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_pw) db.session.add(user) db.session.commit() flash('Your account has been created!', 'success') return redirect(url_for('users.login')) flash('Do not use a real email or password!', 'warning') return render_template('register.html', title="Register", form=form)
def get_statistics_message(self): users = self._select_all() users_amount = 0 followers_amount = 0 invited_amount = 0 for user in users: user = User(db_id=user[0], telegram_id=user[1], balance=user[2], is_follower=user[3], invited_by=user[4]) if user.is_follower: followers_amount += 1 if user.invited_by != 'None': invited_amount += 1 users_amount += 1 return get_statistics_message(users_amount, followers_amount, invited_amount)
def get_invited_users(self, invitor: User): invited_users = [] rows = self._select_all() for row in rows: user = User(db_id=row[0], telegram_id=row[1], balance=row[2], is_follower=row[3], invited_by=row[4]) print(invitor, ':', user) try: if int(invitor.telegram_id) == int(user.invited_by): user.invited_by = 'None' self.update_user(user) invited_users.append(user) except Exception as er: print(er) return invited_users
def any_msg(message): user = User(telegram_id=message.chat.id, username=message.chat.username) if user.not_in_base(): send_welcome(message) else: user = get_user(message.chat.id) if "@" in message.text: user.add_email(message.text) bot.send_message(chat_id=user.user_id, text=content.service_msg['email'] + message.text) elif "+7" in message.text or message.text.isdigit(): user.add_phone_number(message.text) bot.send_message(chat_id=user.user_id, text=content.service_msg['number'] + message.text) else: user.add_name(message.text) bot.send_message(chat_id=user.user_id, text=content.service_msg['name'] + message.text) user.rewrite_user_info()
def get(self, request, *args, **kwargs): name = request.GET.get('name') email = request.GET.get('email') passwd = request.GET.get('passwd') if name and email and passwd: aesObj = aesEncryption() encPassword = aesObj.EncodeAES(passwd) userObj = User(name=name, email=email, password=encPassword) try: userObj.save() uid = userObj.id response = { "success": True, "redirect": "/fbsignup?uid=" + str(uid) } except: response = {"success": False} else: response = {"success": False} return JsonResponse(response)
from modules.models import User from modules import bcrypt,db print("-------------------Admin Account Creation---------------------------------------------------------------") username = input('Enter username: '******'Enter email ID: ') while True: password = input('Password: '******'Confirm Password: '******'utf-8') user = User(username=username ,email=email, password=hashed_password, admin=1) db.session.add(user) db.session.commit() print("Your Username is: "+ username + " Your emailID is: "+email) break else: print('Please enter the password again!!!')
def send_contacts(message): user = User(telegram_id=message.chat.id, username=message.chat.username) if user.not_in_base(): user.add_user_in_db() message = content.service_msg['contacts'] bot.send_message(chat_id=user.user_id, text=message)