public User getUserDetails(String userId) { PreparedStatement ps = null; ResultSet rs = null; User user = null; RegisterService registerService = new RegisterService(); try { ps = connection.prepareStatement("SELECT * FROM user WHERE username=? LIMIT 1"); ps.setString(1, username); rs = ps.executeQuery(); if (rs != null && rs.next()) { user = new User(userId); user.setFirstName(rs.getString("firstname")); user.setLastName(rs.getString("lastname")); user.setEmail(rs.getString("email")); user.setPhoneNumber(rs.getString("primaryPhone")); user.setCellphone(rs.getString("secondaryPhone")); user.setAddress(registerService.createAddressFromID(rs.getInt("addressID"))); user.setCard(registerService.createCardFromID(rs.getInt("creditCardID"))); } } catch (SQLException e) { e.printStackTrace(); } return user; }
public PagedResult<User> readUsers(String source) throws ReviewboardException { try { JSONObject rootObject = checkedGetJSonRootObject(source); int totalResults = rootObject.getInt("total_results"); JSONArray jsonUsers = rootObject.getJSONArray("users"); List<User> users = new ArrayList<User>(); for (int i = 0; i < jsonUsers.length(); i++) { JSONObject jsonUser = jsonUsers.getJSONObject(i); User user = new User(); user.setId(jsonUser.getInt("id")); user.setUrl(jsonUser.getString("url")); user.setUsername(jsonUser.getString("username")); // some fields are not set for private profiles user.setEmail(jsonUser.has("email") ? jsonUser.getString("email") : ""); user.setFirstName(jsonUser.has("first_name") ? jsonUser.getString("first_name") : ""); user.setLastName(jsonUser.has("last_name") ? jsonUser.getString("last_name") : ""); users.add(user); } return PagedResult.create(users, totalResults); } catch (JSONException e) { throw new ReviewboardException(e.getMessage(), e); } }
@RequestMapping(value = "/admin/updateUser.html", method = RequestMethod.POST) public ModelAndView updateUser( String guid, String realName, String phoneNumber, String email, String roleText) { User user = userService.findUserByGuid(guid); user.setRealName(realName); user.setPhoneNumber(phoneNumber); user.setEmail(email); user.setRole(roleText); userService.updateUser(user); return index(); }
public static boolean createAdmin() { User myAdmin = new Admin("admin"); myAdmin.setEmail("*****@*****.**"); myAdmin.setFirstName("FirstAdmin"); myAdmin.setLastName("lastAdmin"); myAdmin.setgNumber("00800000"); myAdmin.setPassword("password"); myAdmin.setPhoneNumber("5555555555"); String username = JOptionPane.showInputDialog(null, "Enter admin username"); String password = JOptionPane.showInputDialog(null, "Enter admin Password"); if (username.equals(myAdmin.getUsername()) && password.equals(myAdmin.getPassword())) { return true; } else { JOptionPane.showMessageDialog( null, "Bad password: **Hint: username = '******' :: password = '******'"); return false; } }
public String execute() throws Exception { UserCredentials currentUserCredentials = currentUserService.getCurrentUser() != null ? currentUserService.getCurrentUser().getUserCredentials() : null; // --------------------------------------------------------------------- // Prepare values // --------------------------------------------------------------------- if (email != null && email.trim().length() == 0) { email = null; } if (rawPassword != null && rawPassword.trim().length() == 0) { rawPassword = null; } // --------------------------------------------------------------------- // Update userCredentials and user // --------------------------------------------------------------------- Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits(); User user = userService.getUser(id); user.setSurname(surname); user.setFirstName(firstName); user.setEmail(email); user.setPhoneNumber(phoneNumber); user.updateOrganisationUnits(new HashSet<OrganisationUnit>(units)); UserCredentials userCredentials = userService.getUserCredentials(user); Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>(); for (String id : selectedList) { UserAuthorityGroup group = userService.getUserAuthorityGroup(Integer.parseInt(id)); if (currentUserCredentials != null && currentUserCredentials.canIssue(group)) { userAuthorityGroups.add(group); } } userCredentials.setUserAuthorityGroups(userAuthorityGroups); if (rawPassword != null) { userCredentials.setPassword( passwordManager.encodePassword(userCredentials.getUsername(), rawPassword)); } if (jsonAttributeValues != null) { AttributeUtils.updateAttributeValuesFromJson( user.getAttributeValues(), jsonAttributeValues, attributeService); } userService.updateUserCredentials(userCredentials); userService.updateUser(user); if (currentUserService.getCurrentUser() == user) { selectionManager.setRootOrganisationUnits(units); selectionManager.setSelectedOrganisationUnits(units); selectionTreeManager.setRootOrganisationUnits(units); selectionTreeManager.setSelectedOrganisationUnits(units); } if (units.size() > 0) { selectionManager.setSelectedOrganisationUnits(units); } return SUCCESS; }
/** * @param userList * @return Student Register new student by prompting them for user info */ public static Student registerStudentAccount(LinkedList<User> userList) { String username = ""; String password = ""; String first = ""; String last = ""; String GNum = ""; String phoneNum = ""; String email = ""; String address = ""; User aStudent = null; // prompt for username until available username is entered do { username = JOptionPane.showInputDialog("Please enter desired username"); aStudent = validateUsername(username, userList); if (aStudent != null) { JOptionPane.showMessageDialog(null, "This username is already in use!\nPlease try again"); } } while (aStudent != null); // create student object aStudent = new Student(username); // prompt for password until valid entry is given do { password = JOptionPane.showInputDialog("Please enter desired password"); if (!aStudent.setPassword(password)) { JOptionPane.showMessageDialog( null, "Password does not meet requirements. Minimum 8 characters\nTry Again.", "Error", JOptionPane.ERROR_MESSAGE); } } while (!aStudent.setPassword(password)); // prompt for first name until valid entry is made do { first = JOptionPane.showInputDialog("Please enter your first name"); if (!aStudent.setFirstName(first)) { JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again."); } } while (!aStudent.setFirstName(first)); // prompt for last name until valid entry is made do { last = (JOptionPane.showInputDialog("Please enter your last name")); if (!aStudent.setLastName(last)) { JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again"); } } while (!aStudent.setLastName(last)); // prompt for G-Number until valid entry is made do { GNum = (JOptionPane.showInputDialog("Please enter your G-number")); if (!aStudent.setgNumber(GNum)) { JOptionPane.showMessageDialog( null, "Invalid entry! Please write your GNumber in this format 00XXXXXX \nPlease try again", "Error", JOptionPane.ERROR_MESSAGE); } } while (!aStudent.setgNumber(GNum)); // prompt for phone number until valid entry is made do { phoneNum = (JOptionPane.showInputDialog("Please enter your phone number")); if (!aStudent.setPhoneNumber(phoneNum)) { JOptionPane.showMessageDialog( null, "Invalid entry. Please write your phone number in XXXXXXXXXX format \nPlease try again", "Error", JOptionPane.ERROR_MESSAGE); } } while (!aStudent.setPhoneNumber(phoneNum)); // prompt for email until valid entry is made do { email = (JOptionPane.showInputDialog("Please enter your Email address")); if (!aStudent.setEmail(email)) { JOptionPane.showMessageDialog( null, "Invalid entry, correct format: [email protected] \nPlease try again", "Error", JOptionPane.ERROR_MESSAGE); } } while (!aStudent.setEmail(email)); // prompt for address until valid entry is made Student nStudent = (Student) aStudent; do { address = (JOptionPane.showInputDialog("Please enter your shipping address")); if (!nStudent.setShippingAddress(address)) { JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again"); } } while (!nStudent.setShippingAddress(address)); JOptionPane.showMessageDialog(null, "Your account has been created"); try { PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("accounts.txt", true))); pw.println( "\r\n-" + aStudent.getFirstName() + "," + aStudent.getLastName() + "," + aStudent.getgNumber() + "," + aStudent.getPassword() + "," + aStudent.getPhoneNumber() + "," + aStudent.getEmail() + "," + aStudent.getUsername() + "," + nStudent.getShippingAddress()); pw.close(); } catch (IOException e) { e.printStackTrace(); } userList.add(aStudent); return nStudent; }
/** @param userList Populate system with list of students accounts from text file */ public static void populateStudentAccounts(LinkedList<User> userList) { Scanner inputStream = null; // open text file of accounts try { inputStream = new Scanner(new FileInputStream("accounts.txt")); // System.out.println("accounts file read"); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, "The file \"accounts.txt\" could not be found"); JOptionPane.showMessageDialog(null, "The system will now exit"); System.exit(0); } // Pull line of text to generate a student while (inputStream.hasNextLine()) { String s1 = inputStream.nextLine(); // locate first name int fNsameStart = (s1.indexOf("-") + 1); int fNameEnd = (s1.indexOf(",")); String fName = s1.substring(fNsameStart, fNameEnd); // locate Last name int lNameStart = (s1.indexOf(",", fNameEnd) + 1); int lNameEnd = (s1.indexOf(",", lNameStart)); String lName = s1.substring(lNameStart, lNameEnd); // locate gNumber int gNumberStart = (s1.indexOf(",", lNameEnd) + 1); int gNumberEnd = (s1.indexOf(",", gNumberStart)); String gNumber = s1.substring(gNumberStart, gNumberEnd); // locate password int passwordStart = (s1.indexOf(",", gNumberEnd) + 1); int passwordEnd = (s1.indexOf(",", passwordStart)); String password = s1.substring(passwordStart, passwordEnd); // locate phone number int phoneNumberStart = (s1.indexOf(",", passwordEnd + 1)); int phoneNumberEnd = (s1.indexOf(",", phoneNumberStart)); String phoneNumber = s1.substring(phoneNumberStart, phoneNumberEnd); // locate email int emailStart = (s1.indexOf(",", phoneNumberEnd) + 1); int emailEnd = (s1.indexOf(",", emailStart)); String email = s1.substring(emailStart, emailEnd); // locate username int usernameStart = (s1.indexOf(",", emailEnd) + 1); int usernameEnd = (s1.indexOf(",", usernameStart)); String username = s1.substring(usernameStart, usernameEnd); // locate address int addressStart = (s1.indexOf(",", usernameEnd) + 1); String address = s1.substring(addressStart); // create student object and populate info User aStudent = new Student(username); aStudent.setFirstName(fName); aStudent.setLastName(lName); aStudent.setgNumber(gNumber); aStudent.setPassword(password); aStudent.setPhoneNumber(phoneNumber); aStudent.setEmail(email); if (aStudent instanceof Student) { ((Student) aStudent).setShippingAddress(address); } // add Student to list userList.add(aStudent); System.out.println(userList.size()); } }
public Integer createUser( Date birthdate, TEthnicity ethnicity, TSex sex, TSex sexLookingFor, Integer height, TColor eyeColor, TColor hairColor, TChoice smoke, TChoice drink, THasChildren haveChildren, TWantsChildren wantsMoreChildren, TMaritalStatus maritalStatus, TBodytype userBodyType, String catchphrase, String aboutme, Integer idealHeightStart, Integer idealHeightEnd, TChoice idealSmokes, TChoice idealDrinks, THasChildren idealHasChildren, TWantsChildren idealWantsChildren, TMaritalStatus idealMaritalStatus, Integer termserviceagreement, Integer profileStatus, Zipcode zipcode, String password, String username, String email, List idealEthnicities, List idealBodyTypes, List idealLookingfor, Zipcode idealZipcode, Integer idealAgeStart, Integer idealAgeEnd, Integer idealDistance) throws Exception { Session session = HibernateSessionFactory.getSession(); Transaction transaction = session.beginTransaction(); User user = new User(); try { user.setEthnicity(ethnicity); user.setBirthdate(birthdate); user.setSex(sex); user.setSexLookingFor(sexLookingFor); user.setEyeColor(eyeColor); user.setHairColor(hairColor); user.setHeight(height); user.setSmoke(smoke); user.setDrink(drink); user.setHaveChildern(haveChildren); user.setWantChildern(wantsMoreChildren); user.setMaritalStatus(maritalStatus); user.setBodyType(userBodyType); user.setCatchphrase(catchphrase); user.setAboutme(aboutme); user.setIdealHeightStart(idealHeightStart); user.setIdealHeightEnd(idealHeightEnd); user.setIdealSmokes(idealSmokes); user.setIdealDrinks(idealDrinks); user.setIdealHasChildern(idealHasChildren); user.setIdealWantsChildern(idealWantsChildren); user.setIdealMaritalStatus(idealMaritalStatus); user.setTermserviceagreement(termserviceagreement); user.setProfileStatus(profileStatus); user.setZipcode(zipcode); user.setPassword(PasswordEncryptor.md5(password)); user.setUserName(username); user.setEmail(email); user.setIdealAgeStart(idealAgeStart); user.setIdealAgeEnd(idealAgeEnd); user.setIdealDistance(idealDistance); user.setIdealZipcode(idealZipcode); user.setIdealEthnicities(idealEthnicities); user.setIdealBodyTypes(idealBodyTypes); user.setIdealLookingfor(idealLookingfor); UserDAO dao = new UserDAO(); dao.addUserOrUpdate(user); transaction.commit(); return user.getUserId(); } catch (Exception e) { transaction.rollback(); throw e; } finally { HibernateSessionFactory.closeSession(); } }
/** Stores to persistence layer initial data. */ @PostConstruct public void init() { if (roleRepository.findByName("ROLE_ADMIN") == null) { Role roleUser = new Role(); roleUser.setName("ROLE_USER"); roleRepository.save(roleUser); Role roleAdmin = new Role(); roleAdmin.setName("ROLE_ADMIN"); roleRepository.save(roleAdmin); User user = new User(); user.setEnabled(true); user.setEmail("admin@admin"); BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); user.setPassword(encoder.encode("admin")); List<Role> roles = new ArrayList<>(); roles.add(roleAdmin); roles.add(roleUser); user.setRoles(roles); userRepository.save(user); // Create account for wallet Account walletAccount = new Account(); walletAccount.setName(context.getMessage("Name.default.account", null, Locale.ENGLISH)); walletAccount.setUser(user); walletAccount.setAmount(new BigDecimal(0)); walletAccount.setCurrency(Currency.getInstance("UAH")); accountRepository.save(walletAccount); Account bankAccount = new Account(); bankAccount.setName("Bank"); bankAccount.setUser(user); bankAccount.setAmount(new BigDecimal(500)); bankAccount.setCurrency(Currency.getInstance("UAH")); accountRepository.save(bankAccount); // Create categories for expenses for (int i = 1; i < 6; i++) { Category category = new Category(); category.setName( context.getMessage("Name" + i + ".default.category", null, Locale.ENGLISH)); category.setType(Operation.EXPENSE); category.setUser(user); categoryRepository.save(category); } // Create categories for incomes for (int i = 6; i < 8; i++) { Category category = new Category(); category.setName( context.getMessage("Name" + i + ".default.category", null, Locale.ENGLISH)); category.setType(Operation.INCOME); category.setUser(user); categoryRepository.save(category); } Transaction transaction1 = new Transaction(); transaction1.setDate(new Date()); transaction1.setAccount(walletAccount); transaction1.setAmount(new BigDecimal(50)); transaction1.setCurrency(Currency.getInstance("UAH")); transaction1.setCategory(categoryRepository.findOne(3)); transaction1.setType(Operation.EXPENSE); transaction1.setComment("McDonalds"); transaction1.setUser(user); transactionRepository.save(transaction1); Transaction transaction2 = new Transaction(); Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); transaction2.setDate(calendar.getTime()); transaction2.setAccount(bankAccount); transaction2.setAmount(new BigDecimal(45)); transaction2.setCurrency(Currency.getInstance("UAH")); transaction2.setCategory(categoryRepository.findOne(7)); transaction2.setType(Operation.INCOME); transaction2.setComment("Festo"); transaction2.setUser(user); transactionRepository.save(transaction2); List<Transaction> transactions = new ArrayList<>(); transactions.add(transaction1); user.setTransactions(transactions); } }