示例#1
0
文件: accounts.py 项目: Gubbi/trackr
    def add_user():
        data.validate(
            required_fields=['id', 'user_name', 'user_email', 'user_phone'],
            error_message='Form has errors')

        org = Organization.get_by_id(data.id)
        if not org:
            return error('Organization not found')

        user = get_user_by_email(data.user_email)
        if not user:
            user = User(raw_name=data.user_name,
                        email=data.user_email,
                        phone=data.user_phone,
                        account_verified=True)
            user.org = [org.key]
        else:
            user.org = list(set(user.org + [org.key]))

        new_password = generate_random_password()
        user.password = web_auth.signed_password(new_password)
        user.put()

        TrackrRoles.get_or_insert('roles',
                                  parent=user.key,
                                  kind=['Admin', 'Staff'])

        mail_body = render('/emails/welcome.mako',
                           new_password=new_password,
                           user=user)
        send_email(data.user_email, mail_body, 'Welcome to Trackr')

        return 'Account Created'
示例#2
0
    def post(self):
        email = self.request.get("edEmail", "")
        name = self.request.get("edName", "")
        address = self.request.get("edAddress", "")
        phone = self.request.get("edPhone", "")
        operation = self.request.get("edOp", "")

        if email and operation:
            if operation == "add":
                user = User()
                user.email = email
                user.name = name
                user.address = address
                user.phone = phone
                user.put()
                time.sleep(1)
            elif operation == "delete":
                user = User.query(User.email == email)
                if user:
                    user = user.get()
                    user.key.delete()
                    time.sleep(1)
                else:
                    self.redirect("/error?msg=user was not found")
            self.redirect("/admin")
        else:
            self.redirect("/error?msg=email and operation needed")

        return
示例#3
0
文件: accounts.py 项目: Gubbi/trackr
    def new():
        data.validate(pricing=Required(float),
                      min_pricing=Required(float),
                      required_fields=[
                          'name', 'id', 'short_code', 'brand_name',
                          'support_number', 'admin_name', 'admin_email',
                          'admin_phone'
                      ],
                      error_message='Form has errors')

        org = Organization.get_by_id(data.id)
        if not org:
            org = Organization(id=data.id,
                               name=data.name,
                               secure_signup_step='Approved')
            set_api_creds(org)
            org.put()

        user = get_user_by_email(data.admin_email)
        if not user:
            user = User(raw_name=data.admin_name,
                        email=data.admin_email,
                        phone=data.admin_phone,
                        account_verified=True)
            user.org = [org.key]
        else:
            user.org = list(set(user.org + [org.key]))

        new_password = generate_random_password()
        user.password = web_auth.signed_password(new_password)
        user.put()

        org.admin = user.key
        org.put()

        if not Trackr.get_by_id(org.key.id()):
            Trackr(id=org.key.id(),
                   org=org.key,
                   users=[user.key],
                   short_code=data.short_code,
                   brand_name=data.brand_name,
                   support_number=data.support_number,
                   secure_pricing=data.pricing,
                   secure_min_pricing=data.min_pricing).put()

        TrackrRoles.get_or_insert('roles',
                                  parent=user.key,
                                  kind=['Admin', 'Staff'])

        mail_body = render('/emails/welcome.mako',
                           new_password=new_password,
                           user=user)
        send_email(data.admin_email, mail_body, 'Welcome to Trackr')

        return 'Account Created'