コード例 #1
0
def user_etl(rec):
    if rec == 'header':
        return ['member_number', 'user_name', 'role', 'password']
    user = User(member_id=get_member_id(rec['member_number']),
                user_name=rec['user_name'])
    user.set_password(rec['password'])
    user.role = UserRole.from_name(rec['role'])
    return user
コード例 #2
0
ファイル: users.py プロジェクト: johnstembridge/DT
def register_user(member_number, user_name, password, email=None, role=UserRole.member, two_phase=False, activate_url=None):
    user_id = 0
    if user_name and password:
        member = get_member(member_number)
        if member:
            if not member.is_active():
                ok, message, message_type = False, 'Sorry, you are not a current member, please contact [email protected]', 'danger'
            else:
                if not match_string(member.email, email):
                    ok, message, message_type = False, 'Email does not match', 'warning'
                else:
                    user = get_user(user_name=user_name)
                    if user and user.member_id != member.id:
                        ok, message, message_type = False, 'User name already in use', 'warning'
                    else:
                        if role == UserRole.member:
                            ok, message, message_type = member.check_credentials(user_name, password)
                            if not ok:
                                return ok, user_id, message, message_type
                        if not member.user:
                            user = User(user_name=user_name, member_id=member.id)
                        else:
                            user = member.user
                            user.user_name = user_name
                        if not user.check_password(password):
                            ok, message, message_type = True, 'Password updated', 'success'
                        else:
                            if two_phase:
                                token, expires = user.get_token(current_app)
                                send_mail(
                                    to=member.email,
                                    sender='*****@*****.**',
                                    cc=[],
                                    subject='Dons Trust Members - registration',
                                    message=render_template('activate.txt',
                                                              full_url_for=full_url_for,
                                                              member=member,
                                                              token=token,
                                                              expires=expires)
                                )
                                ok, message, message_type = True, 'Activation email sent to {}'.format(member.email), 'success'
                            else:
                                ok, message, message_type = True, 'You are now a registered user', 'success'
                        user.set_password(password)
                        if not user.role:
                            user.role = role
                        # else:
                        #     if not role in [role.role for role in user.roles]:
                        #         user.roles += [Role(role=role)]
                        save_user(user)
                        user_id = user.id
        else:
            ok, message, message_type = False, 'Cannot find your membership', 'danger'
    else:
        ok, message, message_type = False, 'Missing user name/password', 'warning'
    return ok, user_id, message, message_type
コード例 #3
0
ファイル: interface.py プロジェクト: johnstembridge/DT
def save_member_contact_details(member_number, details, renewal, commit=True):
    member = get_member(member_number)
    update_member_details(member, details)
    if not member.user:
        member.user = User(role = UserRole.member, user_name=str(member_number))
    member.user.set_password(User.member_password(details['post_code']))

    member.type = member.member_type_at_renewal()
    if renewal:
        update_member_renewal(member, details)

    member.last_updated = datetime.date.today()

    if commit:
        db.session.commit()
    return member
コード例 #4
0
ファイル: interface.py プロジェクト: johnstembridge/DT
def save_member_details(member_number, details):
    if member_number > 0:
        member = get_member(member_number)
    else:
        member = get_new_member()
    update_member_details(member, details)
    if not member.user:
        member.user = User(role = UserRole.member, user_name=str(member_number))
    member.user.set_password(User.member_password(details['post_code']))
    member.status = MemberStatus(details['status'])
    member.start_date = details['start_date']
    member.end_date = details['end_date']
    update_member_payments(member, details)
    update_member_actions(member, details)
    update_member_comments(member, details)

    member.last_updated = datetime.date.today()

    if member.number == 0:
        member.number = next_member_number()
        db.session.add(member)

    db.session.commit()
    return member
コード例 #5
0
ファイル: interface.py プロジェクト: johnstembridge/DT
def get_new_user(role):
    return User(role=role)