def test_is_email(): """Test whether different inputs are considered email addresses.""" assert utils.is_email("*****@*****.**") assert utils.is_email("*****@*****.**") assert not utils.is_email("test@localhost") assert not utils.is_email("test@[email protected]") assert not utils.is_email(5) assert not utils.is_email("asd") assert not utils.is_email("asd") assert not utils.is_email([1, 2, 3, 4]) assert not utils.is_email(4.5)
def _add_payment(self, model, recipient, message, amount): email = recipient if is_email(recipient) else None mobile = recipient if is_mobile(recipient) else None address = recipient if is_address(recipient) else None amount = int(amount * 100) payment = Payment(model, mobile, email, address, message, amount) self.session.add(payment)
def referral_create(): if not use_referrals: return bad_request(web_utils.NOT_AVAILABLE) recipient, api_key, err_response = auth_request_get_single_param( db, "recipient") if err_response: return err_response if not utils.is_email(recipient): return bad_request(web_utils.INVALID_EMAIL) recipient = recipient.lower() user = User.from_email(db.session, recipient) if user: time.sleep(5) return bad_request(web_utils.USER_EXISTS) reward_sender_type = app.config["REFERRAL_REWARD_TYPE_SENDER"] reward_sender = app.config["REFERRAL_REWARD_SENDER"] reward_recipient_type = app.config["REFERRAL_REWARD_TYPE_RECIPIENT"] reward_recipient = app.config["REFERRAL_REWARD_RECIPIENT"] recipient_min_spend = app.config["REFERRAL_RECIPIENT_MIN_SPEND"] ref = Referral(api_key.user, recipient, reward_sender_type, reward_sender, reward_recipient_type, reward_recipient, recipient_min_spend) utils.email_referral(logger, ref) db.session.add(ref) db.session.commit() return 'ok'
def send_email(): if is_email(request.form['email']) and len(request.form['subject']) >= 2 and len(request.form['message']) >= 10: mailer.send_message(request.form['subject'], request.form['message'], request.form['email'], app.config['COPY_MAIL']) flash('Your e-mail was sent succesfully', 'success') else: flash('Please check the form, I don\'t want junk please.','error') return redirect( url_for('show_index') )
def user_register(): content = request.get_json(force=True) if content is None: return bad_request(web_utils.INVALID_JSON) params, err_response = get_json_params(content, [ "email", "password", "first_name", "last_name", "mobile_number", "address", "photo", "photo_type" ]) if err_response: return err_response email, password, first_name, last_name, mobile_number, address, photo, photo_type = params if not utils.is_email(email): return bad_request(web_utils.INVALID_EMAIL) email = email.lower() if not password: return bad_request(web_utils.EMPTY_PASSWORD) if photo and len(photo) > 50000: return bad_request(web_utils.PHOTO_DATA_LARGE) req = UserCreateRequest(first_name, last_name, email, mobile_number, address, photo, photo_type, encrypt_password(password)) user = User.from_email(db.session, email) if user: time.sleep(5) return bad_request(web_utils.USER_EXISTS) utils.email_user_create_request(logger, req, req.MINUTES_EXPIRY) db.session.add(req) db.session.commit() return 'ok'
def validate_recipient(recipient): if not recipient or \ (not is_email(recipient) and not is_mobile(recipient) and not is_address(recipient)): return False ##TODO: direct wallet address not yet implemented if is_address(recipient): return False return True
def send_email(): if is_email(request.form["email"]) and len(request.form["subject"]) >= 2 and len(request.form["message"]) >= 10: mailer.send_message( request.form["subject"], request.form["message"], request.form["email"], app.config["COPY_MAIL"] ) flash("Your e-mail was sent succesfully", "success") else: flash("Please check the form, I don't want junk please.", "error") return redirect(url_for("show_index"))
def process_request(self, request): """The main function which sends feedback and returns status back.""" if request.form: data = request.form self.request["email"], self.request["name"], self.request["feedback"] = [ data.get("email", ""), data.get("name", ""), data.get("feedback", ""), ] if not self.request["email"] or not self.request["name"] or not self.request["feedback"]: self.errors.append("Not all required fields were found.") try: is_email(self.request["email"]) except Exception: self.errors.append("|%s| is not a valid email address." % self.request["email"]) self._send_feedback() return self._output()
def _reward_create(user, reason, category, recipient, amount, message): proposal = Proposal(user, reason) proposal.categories.append(category) proposal.authorize(user) db.session.add(proposal) email = recipient if utils.is_email(recipient) else None mobile = recipient if utils.is_mobile(recipient) else None address = recipient if utils.is_address(recipient) else None payment = Payment(proposal, mobile, email, address, message, amount) db.session.add(payment) return proposal, payment
def prompt_otp_message(n_click, tel_email): assert_button_clicks(n_click) if not tel_email: return S_INPUT_MOBILE_EMAIL if not is_tel(tel_email) and not is_email(tel_email): return S_INPUT_MOBILE_EMAIL user = app_controller.get_club_user_by_tel_or_email(CLUB_NAME, tel_email) if not user: return S_USER_NOT_EXIST app_controller.resend_user_otp(user) return _("Please check you mobile for one time password!")
def process_request(self, request): """The main function which sends feedback and returns status back.""" if request.form: data = request.form self.request['email'], self.request['name'], self.request[ 'feedback'] = [ data.get('email', ''), data.get('name', ''), data.get('feedback', '') ] if not self.request['email'] or not self.request[ 'name'] or not self.request['feedback']: self.errors.append('Not all required fields were found.') try: is_email(self.request['email']) except Exception: self.errors.append('|%s| is not a valid email address.' % self.request['email']) self._send_feedback() return self._output()
def add_user(admin=False): new_user = Users() print 'Add user to database' while True: user_name = raw_input('User (a-z, A-Z, 2-64 chars): ') if test_username(user_name): new_user.user_name = user_name break while True: user_password = getpass.getpass('Password: '******'Password (again): ') if user_password != user_password_again: print "Passwords don't match" else: if test_password(user_password): new_user.set_password(user_password) break while True: user_email = raw_input('Email: ') if is_email(user_email): new_user.user_email = user_email break if admin: new_user.user_restriction = 'admin' else: new_user.user_restriction = 'guest' new_user.user_theme = 'light' try: with session_scope() as db_session: db_session.add(new_user) sys.exit(0) except sqlalchemy.exc.OperationalError: print( "Failed to create user. You most likely need to create the DB before trying to create users.") sys.exit(1) except sqlalchemy.exc.IntegrityError: print("Username already exists.") sys.exit(1)
def validate_email(data) -> bool: """ Validate input for the ``email`` field. It must be a string. Args: data: The data to be validated. Returns: bool: Validation passed. Raises: ValueError: Validation failed. """ if not isinstance(data, str): raise ValueError(f"Not a string ({data})") if data and not utils.is_email(data): raise ValueError(f"Not a valid email address ({data})") return True
def process_question_step(message): try: email = message.text chat_id = message.chat.id if ((not u.is_email(email)) and (email!='nil')): msg = bot.send_message(chat_id, m.email_error) bot.register_next_step_handler(msg, process_human_step) return user = user_dict[chat_id] user.email = email keyboard = types.InlineKeyboardMarkup() btns=[] url_button1 = types.InlineKeyboardButton(text=m.yes, callback_data='to_{}'.format("Yes")) url_button2 = types.InlineKeyboardButton(text=m.no, callback_data='to_{}'.format("No")) btns.append(url_button1) btns.append(url_button2) keyboard.add(*btns) bot.send_message(chat_id, m.question, reply_markup=keyboard) except: msg = bot.send_message(chat_id, m.email_error) bot.register_next_step_handler(msg, process_question_step)
def handle_usernames(result, owner_info): dl = [] if result[0] == 0: atom_dict = result[1] ## ## Here, atom_dict is the list of atoms we passed to ## resolve_to_usernames(), returned as key/value pairs. ## The keys are the atoms we passed, the values are the usernames, ## or None if the atom couldn't be resolved. If None, and the ## key is an email address, create a guest account. ## for key in atom_dict.keys(): if isinstance(atom_dict[key], (list, tuple)): ## ## Must have been a group name ## for username in atom_dict[key]: dl.append(process_user(username, owner_info)) else: if atom_dict[key]: ## ## It was a username or email address, ## and it was resolved successfully. ## dl.append(process_user(atom_dict[key], owner_info)) else: ## ## Couldn't find it. If it's an email ## address, create a guest account. if utils.is_email(key): d3 = self.app.api.users.create_guest(key) d3.addCallback(handle_guest, owner_info) dl.append(d3) else: result_set.append((-1, (key, "Unable to resolve"))) else: raise errors.APIError("Error resolving user atoms") d_list = DeferredList(dl) return d_list
def test_is_email__valid(self): """valid value""" result = utils.is_email('*****@*****.**') self.assertEqual(result, '*****@*****.**') result = utils.is_email('*****@*****.**') self.assertEqual(result, '*****@*****.**')
gs = GroupSelector('user数量') group = gs.group group_list = gs.group_list if group == None: exit(-1) else: email = "" if type(group.node_list[0]) == Vmess: while True: is_duplicate_email = False email = input("是否输入email来新建用户, 回车直接跳过: ") if email == "": break if not is_email(email): print("不是合格的email格式,请重新输入") continue for loop_group in group_list: for node in loop_group.node_list: if node.user_info == None or node.user_info == '': continue elif node.user_info == email: print("已经有重复的email, 请重新输入") is_duplicate_email = True break if not is_duplicate_email: break nw = NodeWriter(group.tag, group.index)
def validate_email(email): if email and not is_email(email): return "invalid email address" return None
def get_club_user_by_tel_or_email(self, club_name, tel_email): if is_tel(tel_email): return self.get_club_user_by_tel(club_name, tel_email) elif is_email(tel_email): return self.get_club_user_by_email(club_name, tel_email) return None
def validate_email_address(form, field): if not is_email(field.data): raise ValidationError('invalid email address format')