def register(): if current_user.is_authenticated: return redirect(url_for('api.index')) form = RegisterForm() if form.validate_on_submit(): account = Account(username=form.username.data, email=form.email.data, displayName=form.display_name.data, createTime=datetime.utcnow()) account.set_password(form.password.data) db.session.add(account) db.session.commit() flash('Congratulations, you are now a registered user!') # return redirect(url_for('api.login')) return 'ok' return render_template('register.html', form=form)
def add(cls, **kwargs): account = Account( phone = kwargs.get('phone', ''), nickname = kwargs.get('nickname', ''), state = 1 ) db.session.add(account) db.session.commit()
def create_user_account(username, password): data = {"email": username, "password": password} status, user_data = sync_engine_account_dispatch(owner_mail=username, account_type="generic", data=data, update=False) if status: try: name, surname = get_name_from_mailcow_db(username) user = User(username=username, name=name, surname=surname) main_account = Account(email=username, password=hashlib.sha256( password.encode()).hexdigest(), is_main=True, uuid=user_data['account_id']) initial_settings = [('email', 'email-filters', []), ('email', 'email-vacation', {}), ('email', 'email-forward', {}), ('email', 'email-general', { "accounts": [], "auto_refresh_every": "30m", "browser_notification": True, "enabled": False })] for settings_type in initial_settings: new_settings = Settings(enabled=False, section=settings_type[0], setting_type=settings_type[1], value=settings_type[2]) new_settings.accounts.append(main_account) user.settings.append(new_settings) user.accounts.append(main_account) db.session.add(user) db.session.commit() return True except: traceback.print_exc() sync_engine_delete_account(user_data['account_id']) db.session.rollback() return False return False
def create_microsoft_account(owner_username, email, data): status, user_data = sync_engine_account_dispatch(owner_mail=owner_username, update=False, data=data, account_type="microsoft") if status: user = User.query.filter(User.username == owner_username).first() new_account = Account.query.filter(Account.email == email).first() if not new_account: new_account = Account(email=email, password=hashlib.sha256( "dummy".encode()).hexdigest(), is_main=False, uuid=user_data['account_id']) user.accounts.append(new_account) db.session.commit() return True return False