Beispiel #1
0
 def generate_secrets(self, secondary_secret_p = True):
   self.primary_secret = utils.random_string(16)
   if secondary_secret_p:
     self.secondary_secret = utils.random_string(6, [string.digits])
   else:
     self.secondary_secret = None
   self.save()
Beispiel #2
0
 def generate_secrets(self, secondary_secret_p=True):
     self.primary_secret = utils.random_string(16)
     if secondary_secret_p:
         self.secondary_secret = utils.random_string(6, [string.digits])
     else:
         self.secondary_secret = None
     self.save()
Beispiel #3
0
  def password_set(self, new_password):
    # generate a new salt
    self.password_salt = utils.random_string(20)

    # compute the hash
    self.password_hash = self.compute_hash(new_password, self.password_salt)
    if self.state == UNINITIALIZED:
      self.set_state(ACTIVE)
Beispiel #4
0
    def password_set(self, new_password):
        # generate a new salt
        self.password_salt = utils.random_string(20)

        # compute the hash
        self.password_hash = self.compute_hash(new_password,
                                               self.password_salt)
        if self.state == UNINITIALIZED:
            self.set_state(ACTIVE)
Beispiel #5
0
def map_user(cls, request, record):
    e = utils.random_string(30) + "@anonymous.smartplatforms.org"

    a = LimitedAccount.objects.create(email=e,
                                      given_name="Anomymous",
                                      family_name="Account")
    a.set_state(ACTIVE)
    a.records.add(record)
    a.save()
    return a
def map_user(cls, request, record):
    e =  utils.random_string(30) + "@anonymous.smartplatforms.org"

    a = LimitedAccount.objects.create(email=e, 
                               given_name="Anomymous", 
                               family_name="Account")
    a.set_state(ACTIVE)
    a.records.add(record)
    a.save()
    return a
Beispiel #7
0
  def save(self, *args, **kwargs):

    if not self.token:
      self.token = utils.random_string(30)

    if self.expires_at == None:
      minutes_to_expire=30
      try:
        minutes_to_expire = settings.MINUTES_TO_EXPIRE_DIRECT_ACCESS
      except: pass

      self.expires_at = datetime.datetime.utcnow() + datetime.timedelta(minutes = minutes_to_expire)
    super(RecordDirectAccessToken, self).save(*args, **kwargs)
Beispiel #8
0
  def reset_password(self):
    new_password = utils.random_string(10)
    self.password = new_password
    self.save()
  
    # send the mail
    subject = utils.render_template_raw('email/password_reset/subject', {'account': self}, type='txt').strip()
    body = utils.render_template_raw('email/password_reset/body', 
                      { 'account'     : self, 
                        'url_prefix'  : settings.SMART_UI_SERVER_LOCATION, 
                        'new_password'  : new_password}, 
                      type='txt')

    utils.send_mail(subject,body, settings.EMAIL_FROM_ADDRESS, [self.contact_email])
Beispiel #9
0
    def save(self, *args, **kwargs):

        if not self.token:
            self.token = utils.random_string(30)
            print "RANDOM", self.token

        if self.expires_at == None:
            minutes_to_expire = 30
            try:
                minutes_to_expire = settings.MINUTES_TO_EXPIRE_DIRECT_ACCESS
            except:
                pass

            self.expires_at = datetime.datetime.utcnow() + datetime.timedelta(
                minutes=minutes_to_expire)
        super(RecordDirectAccessToken, self).save(*args, **kwargs)
Beispiel #10
0
    def reset_password(self):
        new_password = utils.random_string(10)
        self.password = new_password
        self.save()

        # send the mail
        subject = utils.render_template_raw('email/password_reset/subject', {
            'account': self
        },
                                            type='txt').strip()
        body = utils.render_template_raw('email/password_reset/body', {
            'account': self,
            'url_prefix': settings.SMART_UI_SERVER_LOCATION,
            'new_password': new_password
        },
                                         type='txt')

        utils.send_mail(subject, body, settings.EMAIL_FROM_ADDRESS,
                        [self.contact_email])
def LoadAppFromJSON(manifest_string, app_params=None):

  if app_params == None: app_params = {}
  
  if "secret" not in app_params:
    print "No consumer secret among the app params. Generating consumer secret."
    app_params["secret"] =  random_string(16)
    
  print "Consumer secret is '%s'" % app_params["secret"]
  
  r = simplejson.loads(manifest_string)
  secret = app_params["secret"]
 
  messages = app_manifest_structure_validator(r)
  if len(messages) > 0:
      print "WARNING! This app manifest is invalid"
      for m in messages:
        print m

  if "override_index" in app_params:
      r["index"] = app_params["override_index"]

  if "override_icon" in app_params:
      r["icon"] = app_params["override_icon"]

  enabled_by_default = False
  if "enabled_by_default" in app_params:
      enabled_by_default = app_params["enabled_by_default"]

  manifest_string = json.dumps(r, sort_keys=True, indent=4)

  if r["mode"] in ("background", "helper"):
      a = HelperApp.objects.create(
                       description = r["description"],
                       consumer_key = r["id"],
                       secret = secret,
                       name =r["name"],
                       email=r["id"],
                       manifest=manifest_string)
      
  elif r["mode"] in ("ui", "frame_ui"):

      if "optimalBrowserEnvironments" not in r:
          r["optimalBrowserEnvironments"] = ["desktop"]
      if "supportedBrowserEnvironments" not in r:
          r["supportedBrowserEnvironments"] = ["desktop", "mobile", "tablet"]
              
      exists = PHA.objects.filter(email=r["id"])
      assert len(exists) <2, "Found >1 PHA by the name %s"%r["id"]
      if len(exists)==1:
          print exists[0]
          print "deleting, exists."
          exists[0].delete()

      a = PHA.objects.create(
                       description = r["description"],
                       consumer_key = r["id"],
                       secret = secret,
                       name =r["name"],
                       email=r["id"],
                       mode=r["mode"],
                       icon_url=r["icon"],
                       enabled_by_default=enabled_by_default,
                       optimal_environments=",".join(r["optimalBrowserEnvironments"]),
                       supported_environments=",".join(r["supportedBrowserEnvironments"]),
                       manifest=manifest_string)
  else: a = None

  if "index" in r:
      act_name = "main"
      act_url  = r["index"]
      AppActivity.objects.create(app=a, name=act_name, url=act_url)
  
  if "requires" in r:  
    capabilities = get_capabilities()
    for k in r["requires"]:
        if k not in capabilities:
            print "WARNING! This app requires an unsupported datatype:", k
            break
        for m in r["requires"][k]["methods"]:
            if m not in capabilities[k]["methods"]:
                print "WARNING! This app requires an unsupported method:", k, m
                
  if "smart_version" in r:  
    if r["smart_version"] != settings.VERSION:
        print "WARNING! This app requires SMART version", r["smart_version"]

  if "web_hooks" in r:
    for (hook_name, hook_data) in r["web_hooks"].iteritems():
      hook_url = hook_data["url"]

      try: rpc = hook_data['requires_patient_context']
      except: rpc = False
      
      AppWebHook.objects.create(app=a,
                              name=hook_name, 
                              description=hook_data["description"],
                              url=hook_url,
                              requires_patient_context=rpc)
  return a
Beispiel #12
0
def LoadAppFromJSON(manifest_string, app_params=None):
    """ Reads an app manifest
    """
    if app_params == None:
        app_params = {}

    if "secret" not in app_params:
        print "No consumer secret among the app params. Generating consumer secret."
        app_params["secret"] = random_string(16)

    r = simplejson.loads(manifest_string)
    secret = app_params["secret"]

    messages = app_manifest_structure_validator(r)
    if len(messages) > 0:
        msg = "WARNING! This app manifest is invalid: %s (app %s)" % ('. '.join(messages), r['id'])
        raise Exception(msg)

    if "override_index" in app_params:
        r["index"] = app_params["override_index"]

    if "override_icon" in app_params:
        r["icon"] = app_params["override_icon"]

    enabled_by_default = False
    if "enabled_by_default" in app_params:
        enabled_by_default = app_params["enabled_by_default"]

    manifest_string = json.dumps(r, sort_keys=True, indent=4)

    # background app
    if r["mode"] in ("background", "helper"):
        a = HelperApp.objects.create(
            description=r["description"],
            consumer_key=r["id"],
            secret=secret,
            name=r["name"],
            email=r["id"],
            manifest=manifest_string
        )

    # ui app
    elif r["mode"] in ("ui", "frame_ui"):

        # extract optimal environments
        if "optimalBrowserEnvironments" not in r:
            r["optimalBrowserEnvironments"] = ["desktop"]
        if "supportedBrowserEnvironments" not in r:
            r["supportedBrowserEnvironments"] = ["desktop", "mobile", "tablet"]
        opt_browsers = ",".join(r["optimalBrowserEnvironments"])
        sup_browsers = ",".join(r["supportedBrowserEnvironments"])
        
        # extract standalone
        is_standalone = False
        if "standalone" in r:
            is_standalone = r["standalone"]

        exists = PHA.objects.filter(email=r["id"])
        assert len(exists) < 2, "Found >1 PHA by the name %s" % r["id"]
        if len(exists) == 1:
            print exists[0]
            print "deleting, exists."
            exists[0].delete()
        
        a = PHA.objects.create(
            description=r["description"],
            consumer_key=r["id"],
            secret=secret,
            name=r["name"],
            email=r["id"],
            mode=r["mode"],
            standalone=is_standalone,
            icon_url=r["icon"],
            enabled_by_default=enabled_by_default,
            optimal_environments=opt_browsers,
            supported_environments=sup_browsers,
            manifest=manifest_string
        )
    else:
        a = None

    # should probably return here if no App was created
    if a is None:
        return None


    if "requires" in r:
        capabilities = get_capabilities()
        for k in r["requires"]:
            if k not in capabilities:
                print "WARNING! This app requires an unsupported datatype:", k
                break
            for m in r["requires"][k]["methods"]:
                if m not in capabilities[k]["methods"]:
                    print "WARNING! This app requires an unsupported method:", k, m

    if "smart_version" in r:
        if r["smart_version"] != settings.VERSION:
            print "WARNING! This app requires SMART version", r["smart_version"]

    return a