def add_sub(tg_id, source_id): user = Users(db.get_connection()) subscription = Subscription(db.get_connection()) source = Sources(db.get_connection()) user.get_user(tg_id=tg_id) source.get(source_id=source_id) print("add tg_id: ", tg_id) print("add sub_id: ", source_id) if not subscription.create(user.user_id, source_id): bot.send_message(tg_id, f'Вы уже подписаны на "{source.name}".') return bot.send_message(tg_id, f'Подписка на "{source.name}" оформлена.') bot.send_message(tg_id, source.context)
def validate_password_input(self, uname, password): """ Validates user's password input against stored hash :return: """ user_table = Users() user = self.session.query(Users).filter_by(username=uname).one() return user.verify_password(password)
def del_sub(tg_id, source_id): user = Users(db.get_connection()) subscription = Subscription(db.get_connection()) source = Sources(db.get_connection()) user.get_user(tg_id=tg_id) subscription.delete({ 'source_id': source_id, 'user_id': user.user_id }) source.get(source_id=source_id) print("del tg_id: ", tg_id) print("del sub_id: ", source_id) bot.send_message(tg_id, f'Подписка на "{source.name}" отменена.')
def post(self): try: data = request.get_json(force=True) allusers = Users.objects b = True status = 0 message = "User already exists!" for i in allusers: if (i.username == data['username']): b = False if (b): post = Users(username=data['username']) message = "User has been sucessfully created!" status = 1 post.save() return {'status': status, 'message': message} except Exception as e: print(e) return {'status': 300, 'message': "error"}
def take_action(self, parsed_args): repo = UserRepository.get_instance() username = parsed_args.username user = repo.get_by_username(username) if user: raise ValueError(f"{username} is not allowed") generated_password = stru.randstr(len=8) user = Users() user.username = username user.password = cryp.digest_string(generated_password) repo.create(user) user_dir = f"{constants.work_dir()}/{user.username}/_user" os.makedirs(user_dir) print(f"{username} created. Generated password: {generated_password}")
def add_new_user(self, user_info): """ Add a new user to the database :param user_info: a dict containing {name: {FULLNAME}, username: {USERNAME}, password: {PASSWORD}, email: {EMAIL ADDRESS}} :return: code: -1 -> username already exists. -2 -> email already exists. 0 -> success """ result = None name = user_info['name'] uname = user_info['username'] pword = user_info['password'] email_address = user_info['email'] # Check if any of the values are already in the db current_users = self.query_users(uname) try: current_email = result = self.session.query(Users).filter_by( email=email_address).one() if uname == current_users: result = -1 elif email_address == current_email.email: result = -2 except exc.NoResultFound: pass # This is good! We don't want there to be another instance of this. if result is None: try: new_user = Users(full_name=name, username=uname, password=pword, email=email_address) print(name) print(uname) print(pword) print(email_address) self.session.add(new_user) self.session.commit() result = 0 except Exception as e: text = "Could not add new user to database. The add_new_user function returned " \ "{}".format(e) logging.warning(text) print(text) return result
def signup(): form = RegisterForm() if form.validate_on_submit(): hashed_password = generate_password_hash(form.password.data, method="sha256") new_user = Users( username=form.username.data, email=form.email.data, password=hashed_password, ) db.session.add(new_user) db.session.commit() return redirect('/login') return render_template("signup.html", form=form)
def cunhaac_register(): register_error = None if manager.current_user.is_authenticated: return redirect(url_for('cunhaac_dashboard')) if request.method == 'POST': name = request.form['name'] username = request.form['username'] password = request.form['password'] confirm_password = request.form['confirm_password'] email = request.form['email'] if valid_username(username) is False: register_error = 'Username already taken!' if min_chars(password) is False: register_error = 'Password minimum of 8 chars!' if valid_email(email) is False: register_error = 'Invalid email!' if valid_password(password, confirm_password) is False: register_error = 'Passwords do not match!' new_user = Users(name=name, username=username, secure_password=generate_password_hash(password), email=email) if (valid_username(username) and min_chars(password) and valid_email(email) and valid_password(password, confirm_password) is True): try: db.session.add(new_user) db.session.commit() return redirect('/') except Exception as e: return str(e) return render_template('cunhaac_register.html', register_error=register_error)
def post(self, request, sales_id): sales = Sales.objects.get(id=sales_id) if not sales: messages.error(request, f"Data sales tidak ditemukan") return redirect("sales") username = request.POST['username'] password = request.POST['password'] new_obj = Users(username=username, role=2) new_obj.set_password(password) new_obj.save() sales.user_id = new_obj.id sales.save() messages.success( request, f"User untuk sales {sales.nama} berhasil ditambahkan") return redirect("sales")
from database.models import Users, Roles, db username = input('Username to be Admin: ') user = Users.query.filter_by(username=username).first() token = user.get_reset_token() user = Users.verify_reset_token(token) super_role = ('1', 'Administrator', '1') user.roles = list(super_role) db.session.commit()
def get(self, request): users = Users.get_all() ctx = {'users': users} return render(request, 'home.html', ctx)
def get(self, request, u_id): try: user = Users.get_by_id(user_id=u_id) except ValueError: raise Http404 return render(request, 'user/update.html', {'user': user})