Beispiel #1
0
class LoginForm(RedirectForm):
    userid = wtforms.TextField('ID')
    password = wtforms.PasswordField('PW')
    next = wtforms.TextField('next')
    user = None

    def validate(self):
        rv = super().validate()
        if not rv:
            return False

        user = models.User.query.filter_by(username=self.userid.data).first()
        if user is None:
            self.userid.errors.append('존재하지 않는 사용자입니다.')
            return False
        if user.password != self.password.data:
            self.password.errors.append('잘못된 암호입니다.')
            return False

        if not self.next.data:
            self.next.data = '/'
        self.user = user
        return True
Beispiel #2
0
def login():
    login_form = wtforms.form.BaseForm(())
    login_form['username'] = wtforms.TextField("Username")
    login_form['password'] = wtforms.PasswordField("Password")
    login_form['username'].data = ''

    if request.method == 'POST':
        login_form.process(request.form)
        if login_form.validate():
            # login and validate the user...
            password = sha.new(login_form['password'].data).hexdigest()
            u = User.query.filter(User.username == login_form['username'].data,
                                  User.password == password).all()
            if u:
                login_user(u[0])
                flash("Logged in successfully.")
                return redirect(request.args.get("next") or "/admin")
            else:
                flash("Username or password incorrect, try again.")

        return redirect("/login")

    return render_template("login.html", form=login_form)
Beispiel #3
0
class PasswordMixin:

    password = wtforms.PasswordField(validators=[wtforms.validators.DataRequired()])

    def __init__(self, *args, check_password_metrics_tags=None, **kwargs):
        self._check_password_metrics_tags = check_password_metrics_tags
        super().__init__(*args, **kwargs)

    def validate_password(self, field):
        userid = self.user_service.find_userid(self.username.data)
        if userid is not None:
            try:
                if not self.user_service.check_password(
                    userid, field.data, tags=self._check_password_metrics_tags
                ):
                    raise wtforms.validators.ValidationError(
                        "The password is invalid. Try again."
                    )
            except TooManyFailedLogins:
                raise wtforms.validators.ValidationError(
                    "There have been too many unsuccessful login attempts, "
                    "try again later."
                ) from None
Beispiel #4
0
class LoginForm(wtforms.Form):
    email = wtforms.StringField(
        'Email',
        validators=[validators.DataRequired()]
    )
    password = wtforms.PasswordField(
        'Password',
        validators=[validators.DataRequired()]
    )
    remember_me = wtforms.BooleanField(
        'Remember me?',
        default=True
    )

    def validate(self):
        if not super(LoginForm, self).validate():
            return False

        self.user = User.authenticate(self.email.data, self.password.data)
        if not self.user:
            self.email.errors.append('Invalid email or password')
            return False

        return True
Beispiel #5
0
    def login(self):

        login_form = wtforms.form.BaseForm(())
        login_form['username'] = wtforms.TextField("Username")
        login_form['password'] = wtforms.PasswordField("Password")
        login_form['username'].data = ''

        if request.method == 'POST':
            login_form.process(request.form)
            if login_form.validate():
                # login and validate the user...
                login = login_form['username'].data
                password = login_form['password'].data
                try:
                    u = self.do_user_login(login, password)
                    login_user(u)
                    flash("Logged in successfully.")
                    return redirect(request.args.get("next") or "/")
                except:
                    flash("Username or password incorrect, try again.")

            return redirect("/login")

        return render_template("login.html", form=login_form, app=self)
Beispiel #6
0
class PasswordMixin:

    password = wtforms.PasswordField(
        validators=[wtforms.validators.DataRequired()])

    def __init__(self,
                 *args,
                 request,
                 action="login",
                 check_password_metrics_tags=None,
                 **kwargs):
        self.request = request
        self.action = action
        self._check_password_metrics_tags = check_password_metrics_tags
        super().__init__(*args, **kwargs)

    def validate_password(self, field):
        userid = self.user_service.find_userid(self.username.data)
        if userid is not None:
            try:
                if not self.user_service.check_password(
                        userid,
                        field.data,
                        tags=self._check_password_metrics_tags,
                ):
                    self.user_service.record_event(
                        userid,
                        tag=f"account:{self.action}:failure",
                        additional={"reason": "invalid_password"},
                    )
                    raise wtforms.validators.ValidationError(
                        _("The password is invalid. Try again."))
            except TooManyFailedLogins:
                raise wtforms.validators.ValidationError(
                    _("There have been too many unsuccessful login attempts. "
                      "Try again later.")) from None
Beispiel #7
0
class SigninForm(flask_wtf.FlaskForm):

    username = wtforms.StringField("Name:", validators=[vld.DataRequired()])
    password = wtforms.PasswordField("Password:"******"Sign in")
Beispiel #8
0
class UserForm(BaseSecureForm):
    """User form
       Note: no need to add a 'users' field.  Use the user_editor panel (in a template) instead
       Only need to initialize as a secure form to generate CSRF token
    """
    # these fields used for new user form
    random_password = wtforms.BooleanField(
        label=_(u"Create and download random password"))
    access_keys = wtforms.BooleanField(
        label=_(u"Create and download access keys"))
    allow_all = wtforms.BooleanField(label=_(
        u"Allow read/write access to all resource except users and groups"))

    path = wtforms.TextField(label=_(u"Path"), default="/")

    ec2_images_max = wtforms.TextField(label=_(u'Images (maximum)'))
    ec2_instances_max = wtforms.TextField(label=_(u'Instances (maximum)'))
    ec2_volumes_max = wtforms.TextField(label=_(u'Volumes (maximum)'))
    ec2_total_size_all_vols = wtforms.TextField(
        label=_(u'Total size of all volumes (GB)'))
    ec2_snapshots_max = wtforms.TextField(label=_(u'Snapshots (maximum)'))
    ec2_elastic_ip_max = wtforms.TextField(
        label=_(u'Elastic IP addresses (maximum)'))

    s3_buckets_max = wtforms.TextField(label=_(u'Buckets (maximum)'))
    s3_objects_per_max = wtforms.TextField(
        label=_(u'Objects per bucket (maximum)'))
    s3_bucket_size = wtforms.TextField(label=_(u'Size of each bucket (MB)'))
    s3_total_size_all_buckets = wtforms.TextField(
        label=_(u'Total size of all buckets (maximum)'))

    autoscale_groups_max = wtforms.TextField(
        label=_(u'Auto scaling groups (maximum)'))
    launch_configs_max = wtforms.TextField(
        label=_(u'Launch configurations (maximum)'))
    scaling_policies_max = wtforms.TextField(
        label=_(u'Scaling policies (maximum)'))

    elb_load_balancers_max = wtforms.TextField(
        label=_(u'Load balancers (maximum)'))

    iam_groups_max = wtforms.TextField(label=_(u'Groups (maximum)'))
    iam_users_max = wtforms.TextField(label=_(u'Users (maximum)'))
    iam_roles_max = wtforms.TextField(label=_(u'Roles (maximum)'))
    iam_inst_profiles_max = wtforms.TextField(
        label=_(u'Instance profiles (maximum)'))

    # additional items used for update user form
    user_name = wtforms.TextField(label=_(u"Name"))
    email = wtforms.TextField(label=_(u"E-mail address"))
    new_password = wtforms.PasswordField(
        _(u'New password'),
        validators=[
            validators.InputRequired(message=_(u'New Password is required')),
            validators.Length(
                min=6, message=_(u'Password must be more than 6 characters'))
        ],
        widget=widgets.PasswordInput())
    new_password2 = wtforms.PasswordField(
        _(u'Confirm new password'),
        validators=[
            validators.InputRequired(message=_(u'New Password is required')),
            validators.Length(
                min=6, message=_(u'Password must be more than 6 characters'))
        ],
        widget=widgets.PasswordInput())

    download_keys = wtforms.BooleanField(
        label=_(u"Download keys after generation"))

    def __init__(self, request, user=None, conn=None, **kwargs):
        super(UserForm, self).__init__(request, **kwargs)
        self.user = user
        self.conn = conn
        if user is not None:
            self.user_name.data = user.user_name
            self.path.data = user.path
            try:
                policies = self.conn.get_all_user_policies(
                    user_name=user.user_name)
                for policy_name in policies.policy_names:
                    policy_json = self.conn.get_user_policy(
                        user_name=user.user_name,
                        policy_name=policy_name).policy_document
                    policy = json.loads(policy_json)
                    for s in policy['Statement']:
                        try:  # skip statements without conditions
                            s['Condition']
                        except KeyError:
                            continue
                        for cond in s['Condition'].keys():
                            if cond == "NumericLessThanEquals":
                                for val in s['Condition'][cond].keys():
                                    limit = s['Condition'][cond][val]
                                    if val == 'ec2:quota-imagenumber':
                                        self.setLowest(self.ec2_images_max,
                                                       limit)
                                    elif val == 'ec2:quota-vminstancenumber':
                                        self.setLowest(self.ec2_instances_max,
                                                       limit)
                                    elif val == 'ec2:quota-volumenumber':
                                        self.setLowest(self.ec2_volumes_max,
                                                       limit)
                                    elif val == 'ec2:quota-snapshotnumber':
                                        self.setLowest(self.ec2_snapshots_max,
                                                       limit)
                                    elif val == 'ec2:quota-volumetotalsize':
                                        self.setLowest(
                                            self.ec2_total_size_all_vols,
                                            limit)
                                    elif val == 'ec2:quota-addressnumber':
                                        self.setLowest(self.ec2_elastic_ip_max,
                                                       limit)
                                    elif val == 's3:quota-bucketnumber':
                                        self.setLowest(self.s3_buckets_max,
                                                       limit)
                                    elif val == 's3:quota-bucketobjectnumber':
                                        self.setLowest(self.s3_objects_per_max,
                                                       limit)
                                    elif val == 's3:quota-bucketsize':
                                        self.setLowest(self.s3_bucket_size,
                                                       limit)
                                    elif val == 's3:quota-buckettotalsize':
                                        self.setLowest(
                                            self.s3_total_size_all_buckets,
                                            limit)
                                    elif val == 'autoscaling:quota-autoscalinggroupnumber':
                                        self.setLowest(
                                            self.autoscale_groups_max, limit)
                                    elif val == 'autoscaling:quota-launchconfigurationnumber':
                                        self.setLowest(self.launch_configs_max,
                                                       limit)
                                    elif val == 'autoscaling:quota-scalingpolicynumber':
                                        self.setLowest(
                                            self.scaling_policies_max, limit)
                                    elif val == 'elasticloadbalancing:quota-loadbalancernumber':
                                        self.setLowest(
                                            self.elb_load_balancers_max, limit)
                                    elif val == 'iam:quota-groupnumber':
                                        self.setLowest(self.iam_groups_max,
                                                       limit)
                                    elif val == 'iam:quota-usernumber':
                                        self.setLowest(self.iam_users_max,
                                                       limit)
                                    elif val == 'iam:quota-rolenumber':
                                        self.setLowest(self.iam_roles_max,
                                                       limit)
                                    elif val == 'iam:quota-instanceprofilenumber':
                                        self.setLowest(
                                            self.iam_inst_profiles_max, limit)
            except BotoServerError as err:
                pass

    def setLowest(self, item, val):
        """ This function sets the field data value if the new value is lower than the current one """
        if item.data is None or item.data > val:
            item.data = val
Beispiel #9
0
class LoginForm(wtforms.Form):
    username = wtforms.TextField('Username', [wtforms.validators.Length(min=4, max=25)])
    password = wtforms.PasswordField('Password', [wtforms.validators.Length(min=4, max=25), ])
Beispiel #10
0
class AWSLoginForm(BaseSecureForm):
    access_key = wtforms.TextField(_(u'Access key ID'))
    secret_key = wtforms.PasswordField(_(u'Secret key'))
Beispiel #11
0
class Login(flask_wtf.FlaskForm):
    email = wtf.StringField('Email', [valid.Email()])
    password = wtf.PasswordField('Password', [valid.InputRequired()])
    submit = wtf.SubmitField('Login')
Beispiel #12
0
class LoginForm(FlaskForm):
    email = f.StringField('email', validators=[DataRequired()])
    password = f.PasswordField('password', validators=[DataRequired()])
    display = ['email', 'password']
Beispiel #13
0
class UserAdminView(AuthenticateModelView):
    column_list = (
        'name',
        'is_admin',
        'sync_enabled',
        'exchange_username',
        'exchange_last_sync_time',
        'exchange_last_sync_status',
        'cascade_username',
        'cascade_last_sync_time',
        'cascade_last_sync_status',
    )
    form_columns = (
        'name',
        'is_admin',
        'exchange_username',
        'exchange_password_new',
        'exchange_password_confirm',
        'cascade_username',
        'cascade_password_new',
        'cascade_password_confirm',
    )
    form_extra_fields = {
        'exchange_password_new':
        wtf.PasswordField('Exchange Password'),
        'exchange_password_confirm':
        wtf.PasswordField('Exchange Password (Confirm)'),
        'cascade_password_new':
        wtf.PasswordField('Cascade Password'),
        'cascade_password_confirm':
        wtf.PasswordField('Cascade Password (Confirm)'),
    }

    def on_model_change(self, form, model, is_created):
        # Verify the exchange password
        set_exchange_password = check_password_fields(
            form.exchange_password_new,
            form.exchange_password_confirm,
            required=is_created,
        )
        if set_exchange_password:
            model.exchange_password = form.exchange_password_new.data

        # Verify the cascade password
        set_cascade_password = check_password_fields(
            form.cascade_password_new,
            form.cascade_password_confirm,
            required=is_created,
        )
        if set_cascade_password:
            model.cascade_password = form.cascade_password_new.data

        # Continue with the normal validation
        ret = super(UserAdminView,
                    self).on_model_change(form, model, is_created)

        # Check if we added any errors
        if len(form.exchange_password_new.errors) > 0 or len(
                form.cascade_password_new.errors):
            raise ValidationError()

        return ret
Beispiel #14
0
class LoginForm(FlaskForm):
    login = wtforms.StringField(validators=[v.DataRequired()])
    password = wtforms.PasswordField(validators=[v.DataRequired()])
    remember_me = wtforms.BooleanField()
    submit = wtforms.SubmitField()
Beispiel #15
0
class LoginForm(flask_wtf.FlaskForm):
    username = wtforms.StringField('username', validators=[wtforms.validators.InputRequired()])
    password = wtforms.PasswordField('password', validators=[wtforms.validators.InputRequired()])
    remember_me = wtforms.BooleanField('remember_me')
    login = wtforms.SubmitField('Log in')
Beispiel #16
0
class LoginForm(FlaskForm):
    username = wtf.StringField('Username', validators=[v.DataRequired()])
    password = wtf.PasswordField('Password', validators=[v.DataRequired()])
Beispiel #17
0
class UserForm(FlaskForm):
    email = wtf.StringField(
        'Email', [wtf.validators.DataRequired(), wtf.validators.Email()]
    )
    password = wtf.PasswordField("Senha", [wtf.validators.DataRequired()])
    foto = FileField("Foto")
Beispiel #18
0
class LoginForm(MyBaseForm):
    email = wtforms.StringField('Email', [wtforms.validators.Email()])
    password = wtforms.PasswordField(
        'Password', [wtforms.validators.DataRequired()])
    submit = wtforms.SubmitField('Submit')
Beispiel #19
0
class LoginForm(FlaskForm):
    username = wtforms.StringField('Username', validators=[DataRequired()])
    password = wtforms.PasswordField('Password', validators=[DataRequired()])
    remember_me = wtforms.BooleanField('Remember Me')
    submit = wtforms.SubmitField('Sign In')
Beispiel #20
0
class PasswordReset(flask_wtf.FlaskForm):
    password = wtf.PasswordField('Password', [valid.InputRequired()])
    confirm_password = wtf.PasswordField(
        'Confirm Password',
        [valid.EqualTo(password, message="Passwords must match")])
    submit = wtf.SubmitField('Change Password')
Beispiel #21
0
class PasswordWidget(BaseWidget):
    field = wtforms.PasswordField()

    def render_list(self, item):
        return "[password]"
Beispiel #22
0
class Form(flask_wtf.FlaskForm):
    username = wtforms.StringField("Name")
    password = wtforms.PasswordField("Password")
    bio = wtforms.StringField("Bio")
    submit = wtforms.SubmitField("Submit")
Beispiel #23
0
class LoginForm(FlaskForm):
    uname = wtf.TextField('Username', [wtf.validators.required()])
    password = wtf.PasswordField('Password', [wtf.validators.required()])
    submit = wtf.SubmitField('Submit')
Beispiel #24
0
class LoginForm(FlaskForm):
    email = EmailField('이메일', validators=[DataRequired()])
    password = f.PasswordField('비밀번호', validators=[DataRequired()])
    display = ['email', 'password']
class LoginForm(FlaskForm):
    username = wtforms.StringField(
        'Username', validators=[wtforms.validators.DataRequired()])
    password = wtforms.PasswordField(
        'Password', validators=[wtforms.validators.DataRequired()])
    submit = wtforms.SubmitField('Login')
Beispiel #26
0
class LoginForm(FlaskForm):
    login = wtforms.StringField('Email or username',
                                validators=[v.DataRequired()])
    password = wtforms.PasswordField('Password', validators=[v.DataRequired()])
    remember_me = wtforms.BooleanField('Remember me')
    submit = wtforms.SubmitField('Login')
class loginform(FlaskForm):  # 解决警告信息
    username=wtforms.StringField('用户名:',) # 设置username,html页面将从这里取数据
    password=wtforms.PasswordField('密 码:')# 设置password,html页面将从这里取数据
    for1=wtforms.StringField('username',default="我自己")
    for2=wtforms.RadioField("性别",choices=[(1,"男"),(2,"女")])
    for3=wtforms.SelectField("部  门:",choices=[(1,"开发部"),(2,"测试部"),(3,"配置管理部")])
Beispiel #28
0
class SigninForm(flask_wtf.FlaskForm):
    mail = wtf.StringField('Email', )
    pwd  = wtf.PasswordField('Password', )
    submit = wtf.SubmitField('Sign in')
Beispiel #29
0
class loginForm(flask_wtf.FlaskForm):
    name = wtforms.StringField('Input your name',
                               validators=[validators.Required()])
    password = wtforms.PasswordField('Input your password',
                                     validators=[validators.Required()])
    submit = wtforms.SubmitField('Submit')
Beispiel #30
0
class LoginForm(FlaskForm):
    username = wtforms.StringField("Username", [DataRequired()])
    password = wtforms.PasswordField("Password", [DataRequired()])

    submit_button = wtforms.SubmitField("Login")