/** * Saves a user. * * @param user the user to save * @param currentUser the user performing the save operation */ public void saveUser(User user, User currentUser) throws IOException { Assert.notNull(user); Assert.notNull(currentUser); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); Map<String, Object> userMap = new HashMap<String, Object>(); userMap.put("loginName", user.getLoginName()); // $NON-NLS-1$ userMap.put("password", user.getPassword()); // $NON-NLS-1$ userMap.put("email", user.getEmail()); // $NON-NLS-1$ userMap.put("disabled", Boolean.valueOf(user.isDisabled())); // $NON-NLS-1$ if (!user.getOpenIds().isEmpty()) { userMap.put("openIds", user.getOpenIds()); // $NON-NLS-1$ } Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create(); String json = gson.toJson(userMap); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File workingFile = new File(workingDir, user.getLoginName() + USER_SUFFIX); FileUtils.write(workingFile, json, Charsets.UTF_8); Git git = Git.wrap(repo.r()); git.add().addFilepattern(user.getLoginName() + USER_SUFFIX).call(); PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage(user.getLoginName()).call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Util.closeQuietly(repo); } }
// update standard user when they edit their account details // This method uses JDBCTemplate, a spring class used to reduce the amount of code needed to run // queries @Override public void updateUser(User user, String oldUserID) throws SQLException { String query = "UPDATE users SET user_id = ?, first_name = ?, last_name = ?, account_type = ?, email = ?, password = AES_ENCRYPT(?,'.key.') WHERE user_id = ?"; // String query = "UPDATE users SET user_id = ?, first_name = ?, last_name = ?, account_type = // ?, email = ?, password = ? WHERE user_id = ?"; JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); System.out.println( "UPDATE users SET user_id = " + user.getUserID() + ", first_name = " + user.getFirstName() + ", last_name = " + user.getLastName() + ", account_type = " + user.getAccountType() + ", email = " + user.getEmail() + ", password = "******" WHERE user_id = " + oldUserID); Object[] args = new Object[] { user.getUserID(), user.getFirstName(), user.getLastName(), user.getAccountType(), user.getEmail(), user.getPassword(), oldUserID }; jdbcTemplate.update(query, args); }
/** * Validation de l'object m�tier User.<br> * Les r�gles sont les suivantes: * * <ul> * <li>le login est obligatoire * <li>le login est unique * <li>le mot de passse est obligatoire * <li>le nom est obligatoire * <li>le pr�nom est obligatoire * <li>l'email est obligatoire * <li>Le login doit avoir entre 5 et 10 carat�res. * <li>Le mot de passe doit avoir entre 5 et 10 caract�res. * <li>Le format de l'adresse email doit �tre valide * </ul> * * @param object user � valider */ public Errors validate(final Object object) { User user = (User) object; Errors errors = CoreObjectFactory.getErrors(); if (user.getLogin() == null || user.getLogin().trim() == "") { errors.rejectValue("login", "user.loginMandatory"); } else if (user.getLogin().length() < 5 || user.getLogin().length() > 10) { // le login doit avoir entre 5 et 10 caract�res errors.rejectValue("login", "user.loginIncorrectSize"); } else if (user.getPersistanceId() == 0 && userRepository.findUserByLogin(user.getLogin()) != null) { // le login doit �tre unique errors.rejectValue("login", "user.loginAlreadyExists"); } if (user.getPassword() == null || user.getPassword().trim() == "") { errors.rejectValue("password", "user.passwordMandatory"); } else if (user.getPassword().length() < 5 || user.getPassword().length() > 10) { // le password doit avoir entre 5 et 10 caract�res errors.rejectValue("password", "user.passwordIncorrectSize"); } if (user.getLastName() == null || user.getLastName().trim() == "") { errors.rejectValue("lastName", "user.lastNameMandatory"); } if (user.getFirstName() == null || user.getFirstName().trim() == "") { errors.rejectValue("firstName", "user.firstNameMandatory"); } if (user.getEmail() == null || user.getEmail().trim() == "") { errors.rejectValue("email", "user.emailMandatory"); } else if (!EmailValidator.getInstance().isValid(user.getEmail())) { // Le format de l'adresse email doit �tre valide errors.rejectValue("email", "user.incorrectEmail"); } return errors; }
public void addUser(User toAdd) { connect(); try { // Create a stmt object stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // Query the database, storing the result // in an object of type ResultSet rs = stmt.executeQuery( "SELECT * from User WHERE " + "FirstName='" + toAdd.getFirstName() + "' AND " + "LastName='" + toAdd.getLastName() + "' AND " + "Email='" + toAdd.getEmail() + "'"); // Check if User is already in the database while (rs.next()) { System.out.println("User already exists in DB."); disconnect(); return; } // end while loop digest = MessageDigest.getInstance("MD5"); byte[] byteArray = toAdd.getPassword().getBytes(); digest.update(byteArray); // digest.digest( ); byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String md5 = bigInt.toString(16); stmt.executeUpdate( "INSERT INTO User(FirstName, LastName, Email, " + "Password) VALUES ('" + toAdd.getFirstName() + "', '" + toAdd.getLastName() + "', '" + toAdd.getEmail() + "', '" + md5 + "')"); } catch (Exception e) { e.printStackTrace(); } // end catch finally { disconnect(); } }
private Document buildUser(User user) { Element root = new Element(USER_REQUEST_ELEMENT); Document doc = new Document().setRootElement(root); Element data = new Element("data"); root.addContent(data); data.addContent(new Element(USER_ID_ELEMENT).setText(user.getUserId())); data.addContent(new Element(USER_NAME_ELEMENT).setText(user.getName())); data.addContent(new Element(USER_STATUS_ELEMENT).setText(user.getStatus())); data.addContent(new Element(USER_EMAIL_ELEMENT).setText(user.getEmail())); Element roles = new Element(USER_ROLES_ELEMENT); for (String role : user.getRoles()) { roles.addContent(new Element(USER_ROLE_ELEMENT).setText(role)); } data.addContent(roles); data.addContent( new Element(USER_USER_MANAGED_ELEMENT).setText(user.isUserManaged() ? "true" : "false")); return doc; }
@Test public void testFindByEmailFinder() { User user = new User(); user.setEmail("*****@*****.**"); user.setPassword("superSecretPassword"); user.persist(); // Se persisten cambios y se limpia la cache user.flush(); user.entityManager.clear(); // Se busca el usuario recien insertado User user2 = User.findUsersByEmailEquals("*****@*****.**").getSingleResult(); assertEquals(user.getEmail(), user2.getEmail()); assertEquals(user.getId(), user2.getId()); }
@Test public void getReporter() { Issue issue = new Issue(null, Utils.getTestIssue()); assertNotNull(issue.getReporter()); User reporter = issue.getReporter(); assertEquals(reporter.getDisplayName(), "Joseph McCarthy"); assertEquals(reporter.getName(), "joseph"); assertTrue(reporter.isActive()); assertEquals(reporter.getEmail(), "*****@*****.**"); Map<String, String> avatars = reporter.getAvatarUrls(); assertNotNull(avatars); assertEquals(avatars.size(), 4); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=16", avatars.get("16x16")); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=24", avatars.get("24x24")); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=32", avatars.get("32x32")); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=48", avatars.get("48x48")); }
// userdetails의 User를 상속 받아 인증에 필요한 정보를 정보를 포함 할 수 있다. public CurrentUser(User user) { super( user.getEmail(), user.getPasswordHash(), AuthorityUtils.createAuthorityList(user.getRole().toString())); this.user = user; }
@Test public void testFind() throws Exception { User foundUser = h2User.find(user.getId()); assertEquals(email, foundUser.getEmail()); assertEquals(password, foundUser.getPassword()); assertEquals(type, foundUser.getType()); }
public void putAllDetails(User user) { SharedPreferences.Editor spEditor = sharedPreferences.edit(); spEditor.putString("username", user.getUsername()); spEditor.putString("name", user.getName()); spEditor.putString("password", user.getPassword()); spEditor.putString("age", user.getAge()); spEditor.putString("email", user.getEmail()); spEditor.putString("phone", user.getPhone()); spEditor.putString("position", user.getPosition()); spEditor.putString("experience", user.getExperience()); spEditor.putString("curloc", user.getCurloc()); spEditor.putString("desloc", user.getDesloc()); spEditor.putString("imageuri", user.getImageUri()); spEditor.putString("com1name", user.getCom1name()); spEditor.putString("com1pos", user.getCom1pos()); spEditor.putString("com1from", user.getCom1from()); spEditor.putString("com1to", user.getCom1to()); spEditor.putString("com1resp", user.getCom1resp()); spEditor.putString("com2name", user.getCom2name()); spEditor.putString("com2pos", user.getCom2pos()); spEditor.putString("com2from", user.getCom2from()); spEditor.putString("com2to", user.getCom2to()); spEditor.putString("com2resp", user.getCom2resp()); spEditor.putString("com3name", user.getCom3name()); spEditor.putString("com3pos", user.getCom3pos()); spEditor.putString("com3from", user.getCom3from()); spEditor.putString("com3to", user.getCom3to()); spEditor.putString("com3resp", user.getCom3resp()); spEditor.apply(); }
@Test public void getByEmailTest() { User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); assertNotNull(user); }
/** * p>사용자그룹(tm_usergroup)에서 수정한다. * * @param groupID * @return * @throws DataAccessException */ public int updateUser(User user) throws DataAccessException { String sql = QueryUtil.getStringQuery( "admin_sql", "admin.usergroup.updateuser"); // 쿼리 프로퍼티파일의 키값에 해당되는 sql문을 읽어온다. // 넘겨받은 파라미터를 세팅한다. Map<String, Object> param = new HashMap<String, Object>(); param.put("userPWD", user.getUserPWD()); param.put("userName", user.getUserName()); param.put("groupID", user.getGroupID()); param.put("userLevel", user.getUserLevel()); param.put("description", user.getDescription()); param.put("useYN", user.getUseYN()); param.put("userID", user.getUserID()); param.put("isHelper", user.getIsHelper()); param.put("senderName", user.getSenderName()); param.put("email", user.getEmail()); param.put("cellPhone", user.getCellPhone()); param.put("senderEmail", user.getSenderEmail()); param.put("senderCellPhone", user.getSenderCellPhone()); // SQL문이 실행된다. return getSimpleJdbcTemplate().update(sql, param); }
/** * Saves a role. * * @param role the role to save * @param currentUser the user performing the save operation */ public void saveRole(Role role, User currentUser) throws IOException { Assert.notNull(role); Assert.notNull(currentUser); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); Map<String, Object> roleMap = new HashMap<String, Object>(); roleMap.put("name", role.getName()); // $NON-NLS-1$ Set<String> permissions = Sets.newHashSet(); for (Permission permission : role.getPermissions()) { permissions.add(permission.name()); } roleMap.put("permissions", permissions); // $NON-NLS-1$ Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create(); String json = gson.toJson(roleMap); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File workingFile = new File(workingDir, role.getName() + ROLE_SUFFIX); FileUtils.write(workingFile, json, Charsets.UTF_8); Git git = Git.wrap(repo.r()); git.add().addFilepattern(role.getName() + ROLE_SUFFIX).call(); PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage(role.getName()).call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Util.closeQuietly(repo); } }
@Test public void testJSONDeserializer() throws IOException, URISyntaxException { User user = new User(new RestClient(null, new URI("/123/asd")), getTestJSON()); assertEquals(user.getName(), username); assertEquals(user.getDisplayName(), displayName); assertEquals(user.getEmail(), email); assertEquals(user.getId(), userID); Map<String, String> avatars = user.getAvatarUrls(); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=16", avatars.get("16x16")); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=24", avatars.get("24x24")); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=32", avatars.get("32x32")); assertEquals( "https://secure.gravatar.com/avatar/a5a271f9eee8bbb3795f41f290274f8c?d=mm&s=48", avatars.get("48x48")); assertTrue(user.isActive()); }
@RequestMapping(value = "/kkn1234/create", method = RequestMethod.POST) public String formSubmit(@ModelAttribute User user, Model model) throws MalformedURLException, IOException { model.addAttribute("user", user); HttpPost post = new HttpPost( "http://ec2-52-4-138-196.compute-1.amazonaws.com/magento/index.php/customer/account/createpost/"); BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("firstname", user.getFirstName())); nameValuePairs.add(new BasicNameValuePair("lastname", user.getLastName())); nameValuePairs.add(new BasicNameValuePair("email", user.getEmail())); nameValuePairs.add(new BasicNameValuePair("password", user.getPassword())); nameValuePairs.add(new BasicNameValuePair("confirmation", user.getConfirmation())); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(post); response = httpclient.execute(post); System.out.println("Status code is " + response.getStatusLine().getStatusCode()); System.out.println(response.toString()); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println(response.getFirstHeader("Location")); HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); EntityUtils.consume(response.getEntity()); /*File newTextFile = new File("C:\\Users\\Kris\\Desktop\\temp.html"); FileWriter fileWriter = new FileWriter(newTextFile); fileWriter.write(response.toString()); fileWriter.close();*/ return "result"; }
@RequestMapping(method = RequestMethod.GET) public ModelAndView show( @ModelAttribute("form") EditRegisterRequest form, @PathVariable String nick, HttpServletRequest request, HttpServletResponse response) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isSessionAuthorized()) { throw new AccessViolationException("Not authorized"); } if (!tmpl.getNick().equals(nick)) { throw new AccessViolationException("Not authorized"); } User user = tmpl.getCurrentUser(); UserInfo userInfo = userDao.getUserInfoClass(user); ModelAndView mv = new ModelAndView("edit-reg"); form.setEmail(user.getEmail()); form.setUrl(userInfo.getUrl()); form.setTown(userInfo.getTown()); form.setName(user.getName()); form.setInfo(StringEscapeUtils.unescapeHtml(userDao.getUserInfo(user))); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); return mv; }
private void deleteFromAllAuthorities( Predicate<RoleGrantedAuthority> predicate, String commitMessage, User currentUser) throws IOException, GitAPIException { ILockedRepository repo = null; try { List<String> users = listUsers(); users.add(ANONYMOUS_USER_LOGIN_NAME); repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); boolean anyChanged = false; for (String loginName : users) { Set<RoleGrantedAuthority> authorities = Sets.newHashSet(getUserAuthorities(loginName, repo)); Set<RoleGrantedAuthority> newAuthorities = Sets.newHashSet(Sets.filter(authorities, predicate)); if (!newAuthorities.equals(authorities)) { saveUserAuthorities(loginName, newAuthorities, repo, currentUser, false); anyChanged = true; } } if (anyChanged) { PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); Git.wrap(repo.r()) .commit() .setAuthor(ident) .setCommitter(ident) .setMessage(commitMessage) .call(); } } finally { Util.closeQuietly(repo); } }
public void renameRole(String roleName, String newRoleName, User currentUser) throws IOException { Assert.hasLength(roleName); Assert.hasLength(newRoleName); Assert.notNull(currentUser); // check that role exists by trying to load it getRole(roleName); // check that new role does not exist by trying to load it try { getRole(newRoleName); throw new IllegalArgumentException("role already exists: " + newRoleName); // $NON-NLS-1$ } catch (RoleNotFoundException e) { // okay } log.info("renaming role: {} -> {}", roleName, newRoleName); // $NON-NLS-1$ ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File file = new File(workingDir, roleName + ROLE_SUFFIX); File newFile = new File(workingDir, newRoleName + ROLE_SUFFIX); FileUtils.copyFile(file, newFile); Git git = Git.wrap(repo.r()); git.rm().addFilepattern(roleName + ROLE_SUFFIX).call(); git.add().addFilepattern(newRoleName + ROLE_SUFFIX).call(); List<String> users = listUsers(repo); users.add(ANONYMOUS_USER_LOGIN_NAME); for (String user : users) { List<RoleGrantedAuthority> authorities = getUserAuthorities(user, repo); Set<RoleGrantedAuthority> newAuthorities = Sets.newHashSet(); for (Iterator<RoleGrantedAuthority> iter = authorities.iterator(); iter.hasNext(); ) { RoleGrantedAuthority rga = iter.next(); if (rga.getRoleName().equals(roleName)) { RoleGrantedAuthority newRga = new RoleGrantedAuthority(rga.getTarget(), newRoleName); newAuthorities.add(newRga); iter.remove(); } } if (!newAuthorities.isEmpty()) { authorities.addAll(newAuthorities); saveUserAuthorities(user, Sets.newHashSet(authorities), repo, currentUser, false); } } PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit() .setAuthor(ident) .setCommitter(ident) .setMessage("rename role " + roleName + " to " + newRoleName) // $NON-NLS-1$ //$NON-NLS-2$ .call(); } catch (GitAPIException e) { throw new IOException(e); } finally { Util.closeQuietly(repo); } }
private void saveUserAuthorities( String loginName, Set<RoleGrantedAuthority> authorities, ILockedRepository repo, User currentUser, boolean commit) throws IOException, GitAPIException { Map<String, Set<String>> authoritiesMap = new HashMap<String, Set<String>>(); for (RoleGrantedAuthority rga : authorities) { GrantedAuthorityTarget target = rga.getTarget(); String targetStr = target.getType().name() + ":" + target.getTargetId(); // $NON-NLS-1$ Set<String> roleNames = authoritiesMap.get(targetStr); if (roleNames == null) { roleNames = Sets.newHashSet(); authoritiesMap.put(targetStr, roleNames); } roleNames.add(rga.getRoleName()); } Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create(); String json = gson.toJson(authoritiesMap); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File workingFile = new File(workingDir, loginName + AUTHORITIES_SUFFIX); FileUtils.write(workingFile, json, Charsets.UTF_8); Git git = Git.wrap(repo.r()); git.add().addFilepattern(loginName + AUTHORITIES_SUFFIX).call(); if (commit) { PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail()); git.commit().setAuthor(ident).setCommitter(ident).setMessage(loginName).call(); } }
@Test public void getOrganizationsTest() { User user = getUser(UserRole.ROLE_ORG_ADMIN, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); List<Organization> organizations = userService.getOrganizations(user); assertTrue(organizations.size() == 1); }
@Test public void getApplicationsByUserApplicationTypeAppStates() { User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); List<Application> applications = userService.getApplicationsForUser(user, ApplicationType.ANDROID, AppState.GROUP_PUBLISH); assertTrue(applications.size() == 1); }
@Test public void getApplicationVersionsByUserTest() { User user = getUser(UserRole.ROLE_ORG_ADMIN, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); List<ApplicationVersion> applicationVersions = userService.getApplicationVersions(user); assertTrue(applicationVersions.size() == 2); }
@Test public void getGroupsForOrgAdminTest() { User user = getUser(UserRole.ROLE_ORG_ADMIN, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); List<Group> groups = userService.getGroups(user); assertTrue(groups.size() == 1); }
/** * проверка для пользователя с 1-ой звездами * * @throws Exception хм */ @Test public void user1starTest() throws Exception { ResultSet resultSet = Users.getUser1star(); User user = new User(resultSet); Assert.assertEquals(resultSet.getInt("id"), user.getId()); Assert.assertEquals(resultSet.getString("nick"), user.getNick()); Assert.assertTrue(user.matchPassword("passwd")); try { user.checkAnonymous(); } catch (AccessViolationException e) { Assert.fail(); } try { user.checkBlocked(); } catch (AccessViolationException e) { Assert.fail(); } try { user.checkCommit(); Assert.fail(); } catch (AccessViolationException e) { Assert.assertEquals( "Commit access denied for user " + resultSet.getString("nick") + " (" + resultSet.getInt("id") + ") ", e.getMessage()); } Assert.assertFalse(user.isBlocked()); try { user.checkDelete(); Assert.fail(); } catch (AccessViolationException e) { Assert.assertEquals( "Delete access denied for user " + resultSet.getString("nick") + " (" + resultSet.getInt("id") + ") ", e.getMessage()); } Assert.assertFalse(user.canModerate()); Assert.assertFalse(user.isAdministrator()); Assert.assertFalse(user.canCorrect()); Assert.assertFalse(user.isAnonymous()); Assert.assertEquals(resultSet.getInt("score"), user.getScore()); Assert.assertEquals( "<img src=\"/img/normal-star.gif\" width=9 height=9 alt=\"*\">", user.getStatus()); Assert.assertTrue(user.isBlockable()); Assert.assertTrue(user.isActivated()); Assert.assertFalse(user.isAnonymousScore()); Assert.assertEquals(resultSet.getBoolean("corrector"), user.isCorrector()); Assert.assertEquals(resultSet.getString("email"), user.getEmail()); Assert.assertFalse(user.hasGravatar()); Assert.assertEquals(resultSet.getString("name"), user.getName()); }
@Test public void updateTest() { User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER); user.setLastName("Tester"); user = userService.getByEmail(user.getEmail()); userService.update(user); assertEquals(user.getLastName(), "Tester"); }
@Test public void activationTest() { User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); assertFalse(user.isActivated()); boolean activated = userService.activate(user.getId(), user.getActivationCode()); assertTrue(activated); assertTrue(user.isActivated()); }
// User local Database constructor public void storeUserData(User user) { SharedPreferences.Editor spEditor = userLocalDatabase.edit(); spEditor.putString("username", user.getUsername()); spEditor.putString("password", user.getPassword()); spEditor.putString("email", user.getEmail()); spEditor.putString("lastname", user.getLastName()); spEditor.putString("firstname", user.getFirstName()); spEditor.apply(); }
private boolean sendNotification( HttpServletRequest request, HttpServletResponse response, Repository db, String login, String commit, String url, String authorName, String message) throws ServletException, URISyntaxException, IOException, JSONException, CoreException, Exception { UserEmailUtil util = UserEmailUtil.getUtil(); if (!util.isEmailConfigured()) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Smpt server not configured", null)); } IOrionCredentialsService userAdmin = UserServiceHelper.getDefault().getUserStore(); User user = (User) userAdmin.getUser(UserConstants.KEY_LOGIN, login); try { if (reviewRequestEmail == null) { reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE); } String emailAdress = user.getEmail(); util.sendEmail( reviewRequestEmail.getTitle(), reviewRequestEmail .getContent() .replaceAll(EMAIL_COMMITER_NAME, authorName) .replaceAll(EMAIL_URL_LINK, url) .replaceAll(EMAIL_COMMIT_MESSAGE, message), emailAdress); JSONObject result = new JSONObject(); result.put(GitConstants.KEY_RESULT, "Email sent"); OrionServlet.writeJSONResponse( request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } catch (Exception e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "User doesn't exist", null)); } };
public void storePersonal(User user) { SharedPreferences.Editor spEditor = sharedPreferences.edit(); spEditor.putString("username", user.getUsername()); spEditor.putString("name", user.getName()); spEditor.putString("password", user.getPassword()); spEditor.putString("age", user.getAge()); spEditor.putString("email", user.getEmail()); spEditor.putString("phone", user.getPhone()); spEditor.apply(); }
@Test public void getApplicationsByUserApplicationTypeCategoryAppStatesTest() { User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER); user = userService.getByEmail(user.getEmail()); Organization organization = organizationService.getAll().get(0); Category category = organization.getCategories().get(0); List<Application> applications = userService.getApplicationsForUser( user, ApplicationType.ANDROID, category.getId(), AppState.GROUP_PUBLISH); assertTrue(applications.size() == 1); }