Beispiel #1
0
  public static void authenticate(
      @Required String username, String password, String hash, boolean remember) throws Throwable {
    Boolean allowed = false;
    allowed = Security.authenticate(username, password);

    String redirectUrl = flash.get("url");

    if (validation.hasErrors() || !allowed) {
      flash.put("url", redirectUrl);

      flash.error("secure.error");
      params.flash();
      Secure.login();
    }

    session.put("username", username);

    if (remember) {
      response.setCookie("rememberme", Crypto.sign(username) + "-" + username, "30d");
    }

    if (redirectUrl == null) redirectUrl = "/";

    if (hash != null) redirectUrl += hash;

    redirect(redirectUrl);
  }
Beispiel #2
0
 /**
  * Deletes the {@link User} and all it's {@link Question}' {@link Answer}'s {@link Vote}'s.
  *
  * <p>Instead of deleting all {@link Entry}'s of a {@link User}, these entries can optionally be
  * kept in anonymized form by setting their owners to <code>null</code> first.
  *
  * @param anonymize whether to anonymize or just plain delete the user's entries
  * @throws Throwable
  */
 public static void deleteUser(boolean anonymize) throws Throwable {
   User user = Session.user();
   if (anonymize) {
     user.anonymize(true);
   } else {
     Cache.delete("index.questions");
   }
   user.delete();
   flash.success("secure.userdeletedflash");
   Secure.logout();
   Application.index(0);
 }
 public void beforeRoleCheck() {
   // Note that if you provide your own implementation of Secure's Security class you would refer
   // to that instead
   if (!Secure.Security.isConnected()) {
     try {
       if (!session.contains("username")) {
         flash.put("url", "GET".equals(request.method) ? request.url : "/");
         Secure.login();
       }
     } catch (Throwable t) {
       // handle this in an app-specific way
     }
   }
 }
Beispiel #4
0
  /**
   * Descripción de Método
   *
   * @param key
   * @param value
   */
  public static void setProperty(String key, String value) {

    // System.out.println("Ini.set " + key + "=" + value);
    if (s_prop == null) {
      s_prop = new Properties();
    }

    if (key.equals(P_WARNING) || key.equals(P_WARNING_de)) {
      s_prop.setProperty(key, value);
    } else if (!isClient()) {
      s_prop.setProperty(key, Secure.CLEARTEXT + value);
    } else {
      s_prop.setProperty(key, Secure.encrypt(value));
    }
  } // setProperty
Beispiel #5
0
  /**
   * Descripción de Método
   *
   * @param key
   * @param defaultValue
   * @return
   */
  private static String checkProperty(String key, String defaultValue) {

    String result = null;

    if (key.equals(P_WARNING) || key.equals(P_WARNING_de)) {
      result = defaultValue;
    } else if (!isClient()) {
      result = s_prop.getProperty(key, Secure.CLEARTEXT + defaultValue);
    } else {
      result = s_prop.getProperty(key, Secure.encrypt(defaultValue));
    }

    s_prop.setProperty(key, result);

    return result;
  } // checkProperty
Beispiel #6
0
  public static void forget() throws Throwable {

    String username = params.get("username");
    String mobile = params.get("mobile");

    Profile p = Profile.find("user.username=? and contact_phone=?", username, mobile).first();
    if (p == null) {
      flash.error("用户名和手机不匹配,请确认您输入的信息");
      flash.put("username", username);
      toForget();
    } else {
      // SendSMS
      SendMessage m = new SendMessage();
      m.sendSms(p.contact_phone, "您的密码为:" + p.user.password, "0000009");
      flash.success("您的密码已发送您的手机,请查收");
      flash.put("username", username);
      Secure.login();
    }
  }
Beispiel #7
0
  /**
   * Descripción de Método
   *
   * @param key
   * @return
   */
  public static String getProperty(String key) {

    if (key == null) {
      return "";
    }

    String retStr = s_prop.getProperty(key, "");

    if ((retStr == null) || (retStr.length() == 0)) {
      return "";
    }

    //
    String value = Secure.decrypt(retStr);

    // System.out.println("Ini.get " + key + "=" + value);
    if (value == null) {
      return "";
    }

    return value;
  } // getProperty
Beispiel #8
0
  public static void save() throws Throwable {
    String username = params.get("username");
    String name = params.get("name");
    String password = params.get("password");
    String[] materials = params.getAll("material");
    String registration_number = params.get("registration_number");
    String registration_assets = params.get("registration_assets");
    String registration_assets_unit = params.get("registration_assets_unit");
    String registration_address = params.get("registration_address");
    String bank_name = params.get("bank_name");
    String account_name = params.get("account_name");
    String tfn = params.get("tfn");
    String legal_person = params.get("legal_person");
    String factory_name = params.get("factory_name");
    String factory_address = params.get("factory_address");
    String first_supply = params.get("first_supply");
    String business_model = params.get("business_model");
    String contact_name = params.get("contact_name");
    String contact_job = params.get("contact_job");
    String contact_phone = params.get("contact_phone");
    String contact_email = params.get("contact_email");
    String sales_name = params.get("sales_name");
    String sales_job = params.get("sales_job");
    String sales_phone = params.get("sales_phone");
    String[] files = params.getAll("files");

    User user = null;
    Material m = null;
    Files file = null;
    if (username != null && password != null && !"".equals(username) && !"".equals(password)) {
      user = User.find("username=?", username).first();
      if (user == null) {
        user = new User(username, password, ApplicationRole.getByName("user"));
        user.save();
      }

      Profile profile = Profile.find("user.id=?", user.id).first();
      if (profile == null) {
        profile = new Profile();
        profile.user = user;
      }

      if (materials != null) {
        for (String material_id : materials) {
          m = Material.find("id=?", Long.valueOf(material_id.trim())).first();
          if (m != null) profile.materials.add(m);
        }
      }
      profile.name = name;
      profile.registration_number = registration_number;
      profile.registration_assets = registration_assets;
      profile.registration_address = registration_address;
      profile.registration_assets_unit = registration_assets_unit;
      profile.bank_name = bank_name;
      profile.account_name = account_name;
      profile.tfn = tfn;
      profile.legal_person = legal_person;
      profile.factory_name = factory_name;
      profile.factory_address = factory_address;
      profile.first_supply = first_supply;
      profile.business_model = business_model;
      profile.contact_name = contact_name;
      profile.contact_job = contact_job;
      profile.contact_phone = contact_phone;
      profile.contact_email = contact_email;
      profile.sales_name = sales_name;
      profile.sales_job = sales_job;
      profile.sales_phone = sales_phone;

      if (files != null) {
        for (String f : files) {
          file = Files.find("id=?", Long.valueOf(f)).first();
          if (file != null) {
            profile.files.add(file);
          }
        }
      }

      profile.save();
    }

    session.put("username", username);

    Secure.redirectToOriginalURL();
  }
 public static void logout() throws Throwable {
   Secure.logout();
   index();
 }