Exemple #1
0
 public static void authenticate() {
   User user = getUser();
   if (OAuth.isVerifierResponse()) {
     // We got the verifier; now get the access token, store it and back to index
     OAuth.Response oauthResponse =
         OAuth.service(TWITTER).retrieveAccessToken(user.token, user.secret);
     if (oauthResponse.error == null) {
       user.token = oauthResponse.token;
       user.secret = oauthResponse.secret;
       user.save();
     } else {
       Logger.error("Error connecting to twitter: " + oauthResponse.error);
     }
     index();
   }
   OAuth twitt = OAuth.service(TWITTER);
   OAuth.Response oauthResponse = twitt.retrieveRequestToken();
   if (oauthResponse.error == null) {
     // We received the unauthorized tokens in the OAuth object - store it before we proceed
     user.token = oauthResponse.token;
     user.secret = oauthResponse.secret;
     user.save();
     redirect(twitt.redirectUrl(oauthResponse.token));
   } else {
     Logger.error("Error connecting to twitter: " + oauthResponse.error);
     index();
   }
 }
Exemple #2
0
  public static void groupsEdit(String gid) {

    // even if we should skip load for edition reason, we still need to load the real group for the
    // security check
    ProjectGroup group = BeanProvider.getGroupService().loadGroupById(gid, false);

    if (group == null || !group.isActive()) {
      // group does not exist!
      Application.index();
    } else {
      GroupPep pep = new GroupPep(group);
      if (!pep.isUserAllowedToEditGroup(getSessionWrapper().getLoggedInUserProfileId())) {
        // user not allowed to edit this group!
        Application.index();
      } else {

        if (!flash.contains(FLASH_SKIP_LOADING_GROUP)) {
          renderArgs.put("editedGroup", new EditedGroup(group));
        }

        Utils.addThemesToRenderArgs(getSessionWrapper(), renderArgs);
        Utils.addJsonThemesToRenderArgs(
            getSessionWrapper(), renderArgs, getSessionWrapper().getSelectedLg());
        flash.put(FLASH_GROUP_ID, gid);
        render();
      }
    }
  }
  public static void view(String unitId) {

    if (unitId == null) index(true);

    Phone p = Phone.find("unitId = ?", unitId).first();

    if (p == null) index(true);

    List<TripPattern> patterns = TripPattern.find("route.phone = ?", p).fetch();

    render(p, patterns);
  }
  public static void authenticate(String user) {

    System.out.println("authenticate");
    System.out.println("user: "******"verifiedUser: "******"error", "Oops. Authentication has failed");
        login();
      }
      session.put("user", verifiedUser.id);
      index();

    } else {

      System.out.println("about to verify");
      OpenID.id(user).verify(); // will redirect the user
      System.out.println("verified");
    }
  }
Exemple #5
0
  public static void confirmation(
      String courseName,
      @Required(message = "Please specify your name") String name,
      @Required(message = "Please specify your email address") String email,
      String telephonenumber,
      @Required(message = "Please specify company") String company,
      @Required(message = "Please specify billing address") String address,
      String orgnumber) {

    if (Validation.hasErrors()) {
      System.out.println(Validation.errors().toString());
      params.flash(); // add http parameters to the flash scope
      validation.keep(); // keep the errors for the next request
      index();
    }

    Course course = Course.find("byName", courseName).first();

    if (course.isNotFull()) {
      Participant participant =
          new Participant(name, email, telephonenumber, company, address, orgnumber);
      Logger.logInfo(
          participant + " signed up for " + course.name + " starting " + course.startDate);
      course.addParticipant(participant);
      new MailSender().sendConfirmationMail(participant, course);
      flash.success("Thank you for registering for the Kanban Training Class.");

    } else {
      flash.error("Sorry. This course is fully booked");
      registerInterest(course);
    }
    render(course);
  }
 public static void callBack4SQAuth() {
   String code = params.get("code");
   String token = BigBrotherHelper.retrieveToken(code);
   System.out.println(token);
   Application.index();
   // 4square login
 }
Exemple #7
0
 /** Clear the entire database except for the administrator users. */
 public static void clearDB() {
   if (!Session.user().isModerator()) {
     flash.error("secure.cleardberror");
     Application.index(0);
   }
   Database.clearKeepAdmins();
   flash.success("secure.cleardbflash");
   Application.admin();
 }
Exemple #8
0
 @Before
 static void setConnectedUser() {
   if (Security.isConnected()) {
     User user = User.find("byUsername", Security.connected()).first();
     if (!user.isAdmin) {
       flash.error(Messages.get("UserIsNotAuthorized"));
       Application.index();
     }
   }
 }
Exemple #9
0
  /** Clear new notifications. Notifications will no longer appear as new. */
  public static void clearNewNotifications() {
    User user = Session.user();
    for (Notification n : user.getNewNotifications()) {
      n.unsetNew();
    }
    flash.success("secure.notificationsmarkedasreadflash");

    if (!redirectToCallingPage()) {
      Application.index(0);
    }
  }
Exemple #10
0
 @Before
 static void setConnectedUser() {
   renderArgs.put("shopLogoText", Play.configuration.getProperty("bookshop.logotext"));
   if (Security.isConnected()) {
     BookShopUser user = BookShopUser.find("byEmail", Security.connected()).first();
     if (user.isAdmin) {
       renderArgs.put("user", user.fullName);
     } else {
       Application.index();
     }
   }
 }
Exemple #11
0
  /**
   * Delete a notification.
   *
   * @param id the id of the notification to be deleted.
   */
  public static void deleteNotification(int id) {
    User user = Session.user();
    Notification n = user.getNotification(id);
    if (n != null) {
      n.delete();
      flash.success("secure.deletenotificationflash");
    }

    if (!redirectToCallingPage()) {
      Application.index(0);
    }
  }
Exemple #12
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 static void index(String id) {
   List<Produit> listeProduit =
       Produit.find(
               "select distinct p from Produit p join p.marque as m where m.nomMarque = ?", id)
           .fetch();
   if (listeProduit.isEmpty()) {
     flash.success("Il n'y a pas de telephone pour cette marque");
     Application.index();
   } else {
     render(listeProduit);
   }
 }
Exemple #14
0
  /**
   * Load an XML database file
   *
   * @param xml the XML database file to be loaded. This field is mandatory.
   */
  public static void loadXML(@Required File xml) {
    if (!Session.user().isModerator()) {
      Application.index(0);
    }
    if (xml == null) {
      flash.error("secure.xmlselecterror");
      Application.admin();
    }

    try {
      Database.importXML(xml);
      flash.success("secure.xmlloadflash");
    } catch (Throwable e) {
      flash.error("secure.xmlloaderror", e.getMessage());
      e.printStackTrace();
      Application.admin();
    }
    if (xml != null) {
      xml.delete();
    }
    Application.index(0);
  }
Exemple #15
0
  public static void activate(String uuid) {

    Logger.info("用户开始进行激活,uuid" + uuid);
    User user = User.find("uuid", uuid).first();
    Logger.info("start activate:" + user.activated + "id:" + user.id);
    if (user != null) {
      // 激活成功
      user.activated = true;
      user.save();
      Logger.info("user id:" + user.id);
      render("@activatesuccess");

    } else {
      Application.index();
    }
  }
Exemple #16
0
  public static void isLogin(String email, String password) {
    User user = User.find("byEmailAndPasswordAndDeleted", email, password, false).first();
    // 用户名or 密码错误
    if (user == null) {
      render("@login");
    } else {

      // 未激活
      if (user.activated == false) {
        session.put("user", user.email);
        // 跳至激活页面
        render("@notactivate", email);
      }

      session.put("user", user.email);
      Application.index();
    }
  }
Exemple #17
0
  public static void save(
      String firstname, String lastname, String email, String gender, String phonenumber) {
    Profile profile = getCurrentProfile();
    profile.firstname = firstname;
    profile.lastname = lastname;
    profile.email = email;
    profile.gender = gender;
    profile.phonenumber = phonenumber;

    validation.required("firstname", firstname);
    validation.required("lastname", lastname);
    validation.required("email", email);
    validation.required("gender", gender);
    validation.required("phonenumber", phonenumber);

    if (validation.hasErrors()) {
      render("@form", profile);
    } else {
      profile.isComplete = true;
      profile.save();
      Application.index();
    }
  }
 public static void getInvite(@Required @Email String email, String returnUrl) throws Throwable {
   if (validation.hasErrors()) {
     flash.error(Messages.get("web.invite.email.invalid"));
     params.flash();
   } else {
     if (User.findByEmail(email) != null) {
       flash.error(Messages.get("web.invite.email.exists"));
       params.flash();
     } else {
       // Create the invitation instance.
       String lang = Lang.get();
       Invitation invite = new Invitation();
       invite.email = email;
       invite.locale = lang;
       invite.insert();
       flash.success(Messages.get("web.invite.success"));
     }
   }
   if (StringUtils.isBlank(returnUrl)) {
     Application.index();
   }
   redirect(returnUrl);
 }
Exemple #19
0
 public static void logout() {
   session.clear();
   Application.index();
 }
 public static void deleteUser(Long key) throws Neo4jException {
   User user = User.getByKey(key);
   user.delete();
   index();
 }
Exemple #21
0
 public static void scan() {
   scanner.now();
   index();
 }
 public static void decline(long userId, long calendarId, long eventId) {
   User me = Database.users.get(Security.connected());
   me.declineInvitation(userId, calendarId, eventId);
   Application.index(me.getName());
 }
  public static void exportCsv(String unitId) throws IOException {

    Phone p = Phone.find("unitId = ?", unitId).first();

    if (p == null) index(true);

    List<Route> routes = Route.find("phone = ?", p).fetch();

    File outputDirectory =
        new File(Play.configuration.getProperty("application.exportDataDirectory"), unitId);
    File outputZipFile =
        new File(
            Play.configuration.getProperty("application.exportDataDirectory"), unitId + ".zip");

    // write routes
    File routesFile = new File(outputDirectory, unitId + "_routes.csv");
    File stopsFile = new File(outputDirectory, unitId + "_stops.csv");

    if (!outputDirectory.exists()) {
      outputDirectory.mkdir();
    }

    if (outputZipFile.exists()) {
      outputZipFile.delete();
    }

    FileWriter routesCsv = new FileWriter(routesFile);
    CSVWriter rotuesCsvWriter = new CSVWriter(routesCsv);

    FileWriter stopsCsv = new FileWriter(stopsFile);
    CSVWriter stopsCsvWriter = new CSVWriter(stopsCsv);

    String[] routesHeader =
        "unit_id, route_id, route_name, route_description, field_notes, vehicle_type, vehicle_capacity, start_capture"
            .split(",");

    String[] stopsHeader =
        "route_id, stop_sequence, lat, lon, travel_time, dwell_time, board, alight".split(",");

    rotuesCsvWriter.writeNext(routesHeader);
    stopsCsvWriter.writeNext(stopsHeader);

    for (Route r : routes) {

      String[] routeData = new String[routesHeader.length];
      routeData[0] = unitId;
      routeData[1] = r.id.toString();
      routeData[2] = r.routeLongName;
      routeData[3] = r.routeDesc;
      routeData[4] = r.routeNotes;
      routeData[5] = r.vehicleType;
      routeData[6] = r.vehicleCapacity;
      routeData[7] = (r.captureTime != null) ? r.captureTime.toGMTString() : "";

      rotuesCsvWriter.writeNext(routeData);

      List<TripPatternStop> stops = TripPatternStop.find("pattern.route = ?", r).fetch();

      for (TripPatternStop s : stops) {

        String[] stopData = new String[stopsHeader.length];

        stopData[0] = r.id.toString();
        stopData[1] = s.stopSequence.toString();
        stopData[2] = "" + s.stop.location.getCoordinate().y;
        stopData[3] = "" + s.stop.location.getCoordinate().x;
        stopData[4] = "" + s.defaultTravelTime;
        stopData[5] = "" + s.defaultDwellTime;
        stopData[6] = "" + s.board;
        stopData[7] = "" + s.alight;

        stopsCsvWriter.writeNext(stopData);
      }
    }

    rotuesCsvWriter.flush();
    rotuesCsvWriter.close();

    stopsCsvWriter.flush();
    stopsCsvWriter.close();

    DirectoryZip.zip(outputDirectory, outputZipFile);
    FileUtils.deleteDirectory(outputDirectory);

    redirect("/public/data/exports/" + unitId + ".zip");
  }
Exemple #24
0
 static void onAuthenticated() {
   Application.index();
 }
Exemple #25
0
 static void onDisconnected() {
   Application.index();
 }
  public static void cadastrar(String autor, String texto) {
    Recado recado = new Recado(autor, texto);
    recado.save();

    index();
  }
 public static void naoGostei(Long id) {
   Recado recado = Recado.find("id", id).first();
   recado.naoGostei();
   index();
 }
 public static void deletar(Long id) {
   Recado recado = Recado.find("id", id).first();
   recado.delete();
   index();
 }
 public static void logout() throws Throwable {
   Secure.logout();
   index();
 }
Exemple #30
0
 static void onDisconnected() {
   // String username = params.get("username");
   Application.index();
 }