コード例 #1
0
def Super_Admin_Create():

    form = FormRegisterUserAdmin(request.form)

    if form.validate_on_submit():
        User = UserModel()

        role = RoleModel.query(RoleModel.name == 'super_admin').get()
        if not role:
            role = RoleModel()
            role.name = 'super_admin'
            role.visible = False

            role = role.put()
            role = RoleModel.get_by_id(role.id())

        UserRole = UserRoleModel()

        currency = CurrencyModel.query(
            CurrencyModel.code == "XAF"
        ).get()

        if not currency:
            CurrencyCreate = CurrencyModel()
            CurrencyCreate.code = form.currency.data
            CurrencyCreate.name = 'Franc CFA'
            currencyCreate = CurrencyCreate.put()
            currencyCreate = CurrencyModel.get_by_id(currencyCreate.id())
        else:
            currencyCreate = currency

        if role:
            User.first_name = form.first_name.data
            User.last_name = form.last_name.data
            User.email = form.email.data
            User.currency = currencyCreate.key

            password = hashlib.sha224(form.password.data).hexdigest()
            User.password = password

            UserCreate = User.put()
            UserCreate = UserModel.get_by_id(UserCreate.id())

            UserRole.role_id = role.key
            UserRole.user_id = UserCreate.key

            UserRole.put()
        return redirect(url_for('Home'))

    return render_template('user/edit-super-admin.html', **locals())
コード例 #2
0
ファイル: views_user.py プロジェクト: abdounasser202/Achouka
def Super_Admin_Create():

    form = FormRegisterUserAdmin(request.form)

    if form.validate_on_submit():

        try:
            token_mail = str(hashlib.sha224(form.email.data).hexdigest())
            server_url = app_identity.get_default_version_hostname()
            confirm_url = "http://"+server_url+""+url_for('email_confirm', token=token_mail)
            send_mail(sender="*****@*****.**",
                   to=str(form.email.data),
                   subject="Achouka : Confirm your email address",
                   body="""

                   Thank you for creating an account! Please confirm your email address by clicking on the link below:

                   %s

                   """ % confirm_url)

            User = UserModel()
            User.confirmed_token = token_mail
            role = RoleModel.query(RoleModel.name == 'super_admin').get()
            if not role:
                role = RoleModel()
                role.name = 'super_admin'
                role.visible = False

                role = role.put()
                role = RoleModel.get_by_id(role.id())

            UserRole = UserRoleModel()

            currency = CurrencyModel.query(
                CurrencyModel.code == "XAF"
            ).get()

            if not currency:
                CurrencyCreate = CurrencyModel()
                CurrencyCreate.code = "XAF"
                CurrencyCreate.name = 'Franc CFA'
                currencyCreate = CurrencyCreate.put()
                currencyCreate = CurrencyModel.get_by_id(currencyCreate.id())
            else:
                currencyCreate = currency

            if role:
                User.first_name = form.first_name.data
                User.last_name = form.last_name.data
                User.email = form.email.data
                User.currency = currencyCreate.key

                password = hashlib.sha224(form.password.data).hexdigest()
                User.password = password

                UserCreate = User.put()
                UserCreate = UserModel.get_by_id(UserCreate.id())

                UserRole.role_id = role.key
                UserRole.user_id = UserCreate.key

                UserRole.put()
            return redirect(url_for('Home'))
        except InvalidEmailError:
             flash('Your email address is not valid or does not exist', 'danger')

    return render_template('user/edit-super-admin.html', **locals())