diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2af7cef --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..9cc84ea Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..9dda3b6 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..5bf251c --- /dev/null +++ b/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4b629f9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + com.oen.prototype_2 + OklahomaEngagementNetwork + 0.0.1-SNAPSHOT + jar + + OklahomaEngagementNetwork + Second prototype of OEN (formerly EngageOK) + + + org.springframework.boot + spring-boot-starter-parent + 1.5.10.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + + + mysql + mysql-connector-java + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + org.apache.tomcat.embed + tomcat-embed-jasper + + + javax.servlet + jstl + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/src/main/java/com/oen/prototype_2/OklahomaEngagementNetworkApplication.java b/src/main/java/com/oen/prototype_2/OklahomaEngagementNetworkApplication.java new file mode 100644 index 0000000..54c5048 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/OklahomaEngagementNetworkApplication.java @@ -0,0 +1,12 @@ +package com.oen.prototype_2; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OklahomaEngagementNetworkApplication { + + public static void main(String[] args) { + SpringApplication.run(OklahomaEngagementNetworkApplication.class, args); + } +} diff --git a/src/main/java/com/oen/prototype_2/config/WebSecurityConfig.java b/src/main/java/com/oen/prototype_2/config/WebSecurityConfig.java new file mode 100644 index 0000000..a22a0e6 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/config/WebSecurityConfig.java @@ -0,0 +1,46 @@ +package com.oen.prototype_2.config; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +@Configuration +@EnableWebSecurity + public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + private UserDetailsService userDetailsService; + public WebSecurityConfig(UserDetailsService userDetailsService) { + this.userDetailsService = userDetailsService; + } + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } + @Override + protected void configure(HttpSecurity http) throws Exception { + http. + authorizeRequests() + .antMatchers("/style/**", "/registration").permitAll() + .antMatchers("/admin/**").access("hasRole('ADMIN')") + .antMatchers("/org_admin/**").access("hasRole('ORGADMIN')") + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login") + .usernameParameter("email") + .permitAll() + .and() + .logout() + .permitAll(); + } + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder()); + } +} \ No newline at end of file diff --git a/src/main/java/com/oen/prototype_2/controllers/Main.java b/src/main/java/com/oen/prototype_2/controllers/Main.java new file mode 100644 index 0000000..c9e5e48 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/controllers/Main.java @@ -0,0 +1,193 @@ +package com.oen.prototype_2.controllers; + +import java.security.Principal; + +import javax.servlet.http.HttpSession; +import javax.validation.Valid; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +import com.oen.prototype_2.models.Event; +import com.oen.prototype_2.models.Organization; +import com.oen.prototype_2.models.User; +import com.oen.prototype_2.services.UserService; +import com.oen.prototype_2.validator.UserValidator; + +@Controller +public class Main { + private UserService userService; + private UserValidator userValidator; + + public Main(UserService userService, UserValidator uValidator) { + this.userService = userService; + this.userValidator = uValidator; + } + + @RequestMapping("/login") + public String registerForm(@Valid @ModelAttribute("user")User user, @RequestParam(value="error", required=false) String error, @RequestParam(value="logout", required=false) String logout, Model model) { + System.out.println("---login.jsp---"); + if(error != null) { + System.out.println("Unsuccessful LOGIN"); + model.addAttribute("errorMessage", "Your credentials are bad!"); + } + if(logout != null) { + System.out.println("Successful LOGOUT"); + model.addAttribute("logoutMessage", "You have logged out."); + } + return "login.jsp"; + } + + @PostMapping("/registration") + public String registerUser(@Valid @ModelAttribute("user")User user, BindingResult result, Model model, HttpSession session, RedirectAttributes redirectAttributes ) { + System.out.println("-----1-----"); + userValidator.validate(user, result); + System.out.println("-----2-----"); + if(result.hasErrors()) { + return "login.jsp"; + } else { + System.out.println("1"); + int[] anArray; + anArray = new int[0]; + System.out.println(anArray); + System.out.println(userService.findAllUsers()); + if(userService.findAllUsers() == null) { + System.out.println("saving as ADMIN"); + + userService.saveUserWithAdminRole(user); + user.setIsFlagged(false); + user.setNumberOfOrgs(0); + user.setNumberOfEvents(0); + userService.saveUser(user); + return "redirect:/login"; + }else { + System.out.println("saving as USER"); + user.setIsFlagged(false); + user.setNumberOfOrgs(0); + user.setNumberOfEvents(0); + userService.saveWithUserRole(user); + redirectAttributes.addFlashAttribute("regSuc", "Thank you for registering"); + return "redirect:/login"; + } + } + } + + // ENDLOGIN ENDLOGIN ENDLOGIN ENDLOGIN + + //-------------------------------------------------- + + // HOME HOME HOME HOME + + @RequestMapping(value = {"/", "/home"}) + public String home(Principal principal, Model model) { + System.out.println("home"); + String username = principal.getName(); + model.addAttribute("loggedUser", userService.findByEmail(username)); + model.addAttribute("events", userService.findAllEvents()); + return "dashboard.jsp"; + } + + @RequestMapping("/about") + public String about() { + return "about.jsp"; + } + + @RequestMapping("/organization_creation") + public String orgCreate(Principal principal, @Valid @ModelAttribute("organization")Organization organization, BindingResult result, Model model, RedirectAttributes redirectAttributes) { + String username = principal.getName(); + model.addAttribute("loggedUser", userService.findByEmail(username)); + + return "createOrganization.jsp"; + } + + @PostMapping("/organization_creation") + public String createOrg(Principal principal, @Valid @ModelAttribute("organization")Organization organization, BindingResult result, Model model, RedirectAttributes redirectAttributes) { + String username = principal.getName(); + System.out.println(organization.getName()); + System.out.println('-'); + System.out.println(organization.getDescription()); + User user = userService.findByEmail(username); + organization.setLocal_admin(user.getId()); + organization.setNumberOfActivists(0); + + userService.saveOrganization(organization); + return "redirect:/"; + } + + @RequestMapping("/profile/{id}") + public String userPage(@PathVariable("id")Long id, Model model) { + System.out.println("---------user profile------------"); + + model.addAttribute("user", userService.findOneUser(id)); + model.addAttribute("userOrgs", userService.findAllOrganizations()); + model.addAttribute("userEvents", userService.findAllEvents()); + return "userprofile.jsp"; + } + + @RequestMapping("/event_creation/{id}") + public String eventCreate(@PathVariable("id")Long id, Principal principal, @Valid @ModelAttribute("event")Event event, BindingResult result, Model model, RedirectAttributes redirectAttributes) { + System.out.println("---------event creation------------"); + + String username = principal.getName(); + model.addAttribute("loggedUser", userService.findByEmail(username)); + return "createEvent.jsp"; + } + + @PostMapping("/event_creation/event_creation") + public String createEvent(Principal principal, @Valid @ModelAttribute("event")Event event, BindingResult result, Model model, RedirectAttributes redirectAttributes) { + System.out.println("---------ATTEMPTING event create---------------"); + String username = principal.getName(); + System.out.println(event.getName()); + System.out.println('-'); + System.out.println(event.getDescription()); + User user = userService.findByEmail(username); + event.setUser_id(user.getId()); + userService.saveEvent(event); + return "redirect:/"; + } + + @RequestMapping("/eventpage/{id}") + public String eventPage(Principal principal, @PathVariable("id")Long id, Model model) { + String username = principal.getName(); + model.addAttribute("loggedUser", userService.findByEmail(username)); + model.addAttribute("event", userService.findOneEvent(id)); + model.addAttribute("userOrgs", userService.findAllOrganizations()); + model.addAttribute("userEvents", userService.findAllEvents()); + Long userStarted = userService.findOneEvent(id).getUser_id(); + User userStartedBy = userService.findOneUser(userStarted); + model.addAttribute("userStartedBy", userStartedBy); + return "eventpage.jsp"; + } + + @RequestMapping("/editProfile/{id}") + public String editProfile(Principal principal, @PathVariable("id")Long id, Model model, @Valid @ModelAttribute("user")User user, RedirectAttributes redirectAttributes) { + String username = principal.getName(); + model.addAttribute("loggedUser", userService.findByEmail(username)); + return "editProfile.jsp"; + } + + @PostMapping("/editProfile/editProfile") + public String profileEdit(Principal principal, @Valid @ModelAttribute("user")User user, BindingResult result, Model model, RedirectAttributes redirectAttributes, @RequestParam(value="first_name")String first_name, @RequestParam(value="last_name")String last_name, @RequestParam(value="zipcode")Integer zipcode, @RequestParam(value="password")String password, @RequestParam(value="username")String username) { + System.out.println("---------ATTEMPTING EDIT user---------------"); + + + String username1 = principal.getName(); + model.addAttribute("loggedUser", userService.findByEmail(username1)); + User userToEdit = userService.findByEmail(username1); + userToEdit.setFirst_name(first_name); + userToEdit.setLast_name(last_name); + userToEdit.setZipcode(zipcode); + userToEdit.setPassword(password); + userToEdit.setUsername(username); + userService.saveUser(userToEdit); + return "redirect:/"; + } + +} // END Main.java \ No newline at end of file diff --git a/src/main/java/com/oen/prototype_2/models/Comment.java b/src/main/java/com/oen/prototype_2/models/Comment.java new file mode 100644 index 0000000..6f719b0 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/Comment.java @@ -0,0 +1,83 @@ +package com.oen.prototype_2.models; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +@Entity +@Table(name="comments") +public class Comment { + @Id + @GeneratedValue + private Long id; + + @Size(min=1, message="Comment must have content") + private String content; + + private String madeBy; + + + + @Column(updatable=false) + private Date createdAt; + + private Date updatedAt; + + // + + public Comment() {} + + // GETTERS AND SETTERS + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getMadeBy() { + return madeBy; + } + + public void setMadeBy(String madeBy) { + this.madeBy = madeBy; + } + + + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + +} diff --git a/src/main/java/com/oen/prototype_2/models/Event.java b/src/main/java/com/oen/prototype_2/models/Event.java new file mode 100644 index 0000000..9715875 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/Event.java @@ -0,0 +1,154 @@ +package com.oen.prototype_2.models; + +import java.util.Date; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +// Event needs its own associated image + +@Entity +@Table(name="events") +public class Event { + @Id + @GeneratedValue + private Long id; + + @Size(min=1, message="Name cannot be blank") + private String name; + + @Size(min=1, message="Description cannot be blank") + private String description; + + private String location; + + private Long user_id; + + private Date date; + + @Column(updatable=false) + private Date createdAt; + + private Date updatedAt; + + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable( + name = "events_users", + joinColumns = @JoinColumn(name = "event_id"), + inverseJoinColumns = @JoinColumn(name = "user_id") + ) + private List users; + + @ManyToOne(fetch=FetchType.LAZY) + @JoinColumn(name="organization") + private Organization organization; + // + + public Event() {} + + // GETTERS AND SETTERS + + + public Long getId() { + return id; + } + + public Organization getOrganization() { + return organization; + } + + public void setOrganization(Organization organization) { + this.organization = organization; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Long getUser_id() { + return user_id; + } + + public void setUser_id(Long user_id) { + this.user_id = user_id; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + @PreUpdate + protected void onUpdate() { + this.updatedAt = new Date(); + } + + @PrePersist + protected void onCreate() { + this.createdAt = new Date(); + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + +} + diff --git a/src/main/java/com/oen/prototype_2/models/Issuetag.java b/src/main/java/com/oen/prototype_2/models/Issuetag.java new file mode 100644 index 0000000..381a25d --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/Issuetag.java @@ -0,0 +1,73 @@ +package com.oen.prototype_2.models; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +@Entity +@Table(name="issuetags") +public class Issuetag { + @Id + @GeneratedValue + private Long id; + + private String description; + + private String name; + + @ManyToMany(fetch=FetchType.LAZY) + @JoinTable( + name = "orgs_tags", + joinColumns = @JoinColumn(name = "tag_id"), + inverseJoinColumns = @JoinColumn(name = "org_id") + ) + private List organizations; + + // + + public Issuetag() {} + + // GETTERS AND SETTERS + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getOrganizations() { + return organizations; + } + + public void setOrganizations(List organizations) { + this.organizations = organizations; + } + + + +} diff --git a/src/main/java/com/oen/prototype_2/models/Organization.java b/src/main/java/com/oen/prototype_2/models/Organization.java new file mode 100644 index 0000000..bd843a4 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/Organization.java @@ -0,0 +1,138 @@ +package com.oen.prototype_2.models; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +// should have image associated on organization page + +@Entity +@Table(name="organizations") +public class Organization { + @Id + @GeneratedValue + private Long id; + + @Size(min=1, message="Name cannot be blank") + private String name; + + @Size(min=1, message="Description must be longer. Add a little extra!") + private String description; + + private Long local_admin; + + @ManyToMany(fetch=FetchType.LAZY) + @JoinTable( + name = "orgs_users", + joinColumns = @JoinColumn(name = "org_id"), + inverseJoinColumns = @JoinColumn(name = "user_id") + ) + private List users; + + private Integer numberOfActivists; + + private String location; + + @ManyToMany(fetch=FetchType.LAZY) + @JoinTable( + name = "orgs_tags", + joinColumns = @JoinColumn(name = "org_id"), + inverseJoinColumns = @JoinColumn(name = "tag_id") + ) + private List issuetags; + + @OneToMany(mappedBy="organization", fetch=FetchType.LAZY) + private List events; + + // + + public Organization() {} + + // GETTERS AND SETTERS + + + + + public Long getId() { + return id; + } + + public List getIssuetags() { + return issuetags; + } + + public void setIssuetags(List issuetags) { + this.issuetags = issuetags; + } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Long getLocal_admin() { + return local_admin; + } + + public void setLocal_admin(Long local_admin) { + this.local_admin = local_admin; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public Integer getNumberOfActivists() { + return numberOfActivists; + } + + public void setNumberOfActivists(Integer numberOfActivists) { + this.numberOfActivists = numberOfActivists; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + +} diff --git a/src/main/java/com/oen/prototype_2/models/Post.java b/src/main/java/com/oen/prototype_2/models/Post.java new file mode 100644 index 0000000..dccc5f9 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/Post.java @@ -0,0 +1,93 @@ +package com.oen.prototype_2.models; + +import java.util.Date; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +@Entity +@Table(name="posts") +public class Post { + @Id + @GeneratedValue + private Long id; + + @Size(min=1, message="Post must have content") + private String content; + + private String madeBy; + + + + @Column(updatable=false) + private Date createdAt; + + private Date updatedAt; + + // + + public Post() {} + + // GETTERS AND SETTERS + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getMadeBy() { + return madeBy; + } + + public void setMadeBy(String madeBy) { + this.madeBy = madeBy; + } + + + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + + + + + + + + + + + +} diff --git a/src/main/java/com/oen/prototype_2/models/Role.java b/src/main/java/com/oen/prototype_2/models/Role.java new file mode 100644 index 0000000..4eaa179 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/Role.java @@ -0,0 +1,52 @@ +package com.oen.prototype_2.models; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; + +@Entity +@Table(name="roles") +public class Role { + @Id + @GeneratedValue + private Long id; + private String name; + + + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "roles") + private List users; + + + + public Role() { + } + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + +} diff --git a/src/main/java/com/oen/prototype_2/models/User.java b/src/main/java/com/oen/prototype_2/models/User.java new file mode 100644 index 0000000..94d8fe8 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/models/User.java @@ -0,0 +1,231 @@ +package com.oen.prototype_2.models; + +import java.util.Date; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Transient; +import javax.validation.constraints.Size; + +@Entity +@Table(name="users") +public class User { + + @Id + @GeneratedValue + private Long id; + + @Size(min=1, message="Email cannot be blank") + private String email; + + @Size(min=1, message="First name cannot be blank") + private String first_name; + + @Size(min=1, message="Last name cannot be blank") + private String last_name; + + @Size(min=1, message="Username cannot be blank") + private String username; + + @Size(min=5, message="Password must be greater than 5 characters") + private String password; + + @Transient + private String passwordConfirmation; + + @Column(updatable=false) + private Date createdAt; + + private Date updatedAt; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "users_roles", + joinColumns = @JoinColumn(name = "user_id"), + inverseJoinColumns = @JoinColumn(name = "role_id")) + private List roles; + + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable( + name = "orgs_users", + joinColumns = @JoinColumn(name = "org_id"), + inverseJoinColumns = @JoinColumn(name = "user_id") + ) + private List organizations; + + @ManyToMany(fetch = FetchType.LAZY, mappedBy="users") + private List events; + + private Integer numberOfOrgs; + + private Integer numberOfEvents; + + private Boolean isFlagged; + + private Integer zipcode; + + private Boolean isSearching; + // + + public User() {} + + // GETTERS AND SETTERS + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getFirst_name() { + return first_name; + } + + public void setFirst_name(String first_name) { + this.first_name = first_name; + } + + public String getLast_name() { + return last_name; + } + + public void setLast_name(String last_name) { + this.last_name = last_name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPasswordConfirmation() { + return passwordConfirmation; + } + + public void setPasswordConfirmation(String passwordConfirmation) { + this.passwordConfirmation = passwordConfirmation; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + public List getOrganizations() { + return organizations; + } + + public void setOrganizations(List organizations) { + this.organizations = organizations; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + + public Integer getNumberOfOrgs() { + return numberOfOrgs; + } + + public void setNumberOfOrgs(Integer numberOfOrgs) { + this.numberOfOrgs = numberOfOrgs; + } + + public Integer getNumberOfEvents() { + return numberOfEvents; + } + + public void setNumberOfEvents(Integer numberOfEvents) { + this.numberOfEvents = numberOfEvents; + } + + @PreUpdate + protected void onUpdate() { + this.updatedAt = new Date(); + } + + @PrePersist + protected void onCreate() { + this.createdAt = new Date(); + } + + public Boolean getIsFlagged() { + return isFlagged; + } + + public void setIsFlagged(Boolean isFlagged) { + this.isFlagged = isFlagged; + } + + public Integer getZipcode() { + return zipcode; + } + + public void setZipcode(Integer zipcode) { + this.zipcode = zipcode; + } + + public Boolean getIsSearching() { + return isSearching; + } + + public void setIsSearching(Boolean isSearching) { + this.isSearching = isSearching; + } + + + +} \ No newline at end of file diff --git a/src/main/java/com/oen/prototype_2/repositories/EventRepo.java b/src/main/java/com/oen/prototype_2/repositories/EventRepo.java new file mode 100644 index 0000000..db93d15 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/repositories/EventRepo.java @@ -0,0 +1,13 @@ +package com.oen.prototype_2.repositories; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; + +import com.oen.prototype_2.models.Event; + +public interface EventRepo extends CrudRepository { + public List findAll(); + public Event save(Event e); + public Event findOne(Long id); +} \ No newline at end of file diff --git a/src/main/java/com/oen/prototype_2/repositories/IssuetagRepo.java b/src/main/java/com/oen/prototype_2/repositories/IssuetagRepo.java new file mode 100644 index 0000000..6dcc686 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/repositories/IssuetagRepo.java @@ -0,0 +1,13 @@ +package com.oen.prototype_2.repositories; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; + +import com.oen.prototype_2.models.Issuetag; + +public interface IssuetagRepo extends CrudRepository{ + public List findAll(); + public Issuetag save(Issuetag it); + public Issuetag findOne(Long id); +} diff --git a/src/main/java/com/oen/prototype_2/repositories/OrganizationRepo.java b/src/main/java/com/oen/prototype_2/repositories/OrganizationRepo.java new file mode 100644 index 0000000..8899734 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/repositories/OrganizationRepo.java @@ -0,0 +1,13 @@ +package com.oen.prototype_2.repositories; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; + +import com.oen.prototype_2.models.Organization; + +public interface OrganizationRepo extends CrudRepository { + public List findAll(); + public Organization save(Organization o); + public Organization findOne(Long id); +} diff --git a/src/main/java/com/oen/prototype_2/repositories/RoleRepo.java b/src/main/java/com/oen/prototype_2/repositories/RoleRepo.java new file mode 100644 index 0000000..89dfd6b --- /dev/null +++ b/src/main/java/com/oen/prototype_2/repositories/RoleRepo.java @@ -0,0 +1,14 @@ +package com.oen.prototype_2.repositories; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.oen.prototype_2.models.Role; + +@Repository +public interface RoleRepo extends CrudRepository{ + List findAll(); + List findByName(String name); +} diff --git a/src/main/java/com/oen/prototype_2/repositories/UserRepo.java b/src/main/java/com/oen/prototype_2/repositories/UserRepo.java new file mode 100644 index 0000000..d5810b5 --- /dev/null +++ b/src/main/java/com/oen/prototype_2/repositories/UserRepo.java @@ -0,0 +1,19 @@ +package com.oen.prototype_2.repositories; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.oen.prototype_2.models.User; + +@Repository +public interface UserRepo extends CrudRepository{ + public List findAll(); + + public User save(User u); + + User findByEmail(String email); + + User findOne(Long id); +} diff --git a/src/main/java/com/oen/prototype_2/services/UserDetailsServiceImplementation.java b/src/main/java/com/oen/prototype_2/services/UserDetailsServiceImplementation.java new file mode 100644 index 0000000..5f8f52b --- /dev/null +++ b/src/main/java/com/oen/prototype_2/services/UserDetailsServiceImplementation.java @@ -0,0 +1,41 @@ +package com.oen.prototype_2.services; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import com.oen.prototype_2.models.Role; +import com.oen.prototype_2.models.User; +import com.oen.prototype_2.repositories.UserRepo; + +@Service +public class UserDetailsServiceImplementation implements UserDetailsService { + private UserRepo uRepo; + public UserDetailsServiceImplementation(UserRepo uRepo){ + this.uRepo = uRepo; + } + // 1 + @Override + public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { + User user = uRepo.findByEmail(email); + if(user == null) { + throw new UsernameNotFoundException("User not found"); + } + return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), getAuthorities(user)); + } + // 2 + private List getAuthorities(User user){ + List authorities = new ArrayList(); + for(Role role : user.getRoles()) { + GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role.getName()); + authorities.add(grantedAuthority); + } + return authorities; + } +} \ No newline at end of file diff --git a/src/main/java/com/oen/prototype_2/services/UserService.java b/src/main/java/com/oen/prototype_2/services/UserService.java new file mode 100644 index 0000000..57d6fda --- /dev/null +++ b/src/main/java/com/oen/prototype_2/services/UserService.java @@ -0,0 +1,110 @@ +package com.oen.prototype_2.services; + +import java.util.List; + +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; + +import com.oen.prototype_2.models.Event; +import com.oen.prototype_2.models.Issuetag; +import com.oen.prototype_2.models.Organization; +import com.oen.prototype_2.models.User; +import com.oen.prototype_2.repositories.EventRepo; +import com.oen.prototype_2.repositories.IssuetagRepo; +import com.oen.prototype_2.repositories.OrganizationRepo; +import com.oen.prototype_2.repositories.RoleRepo; +import com.oen.prototype_2.repositories.UserRepo; + +@Service +public class UserService { + private final UserRepo uRepo; + private RoleRepo rRepo; + private EventRepo eRepo; + private OrganizationRepo oRepo; + private IssuetagRepo itRepo; + private BCryptPasswordEncoder bCryptPasswordEncoder; + + public UserService(UserRepo uRepo, RoleRepo rRepo, EventRepo eRepo, OrganizationRepo oRepo, IssuetagRepo itRepo, BCryptPasswordEncoder bCryptPasswordEncoder) { + this.uRepo = uRepo; + this.rRepo = rRepo; + this.eRepo = eRepo; + this.oRepo = oRepo; + this.itRepo = itRepo; + this.bCryptPasswordEncoder = bCryptPasswordEncoder; + } + + // USER SERVICES + + public void saveWithUserRole(User user) { + user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); + user.setRoles(rRepo.findByName("ROLE_USER")); + uRepo.save(user); + } + public void saveUserWithAdminRole(User user) { + System.out.println("2"); + user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); + user.setRoles(rRepo.findByName("ROLE_ADMIN")); + uRepo.save(user); + } + public void saveUser(User u) { + u.setPassword(bCryptPasswordEncoder.encode(u.getPassword())); + + uRepo.save(u); + } + + public User findByEmail(String email) { + return uRepo.findByEmail(email); + } + + public List findAllUsers(){ + return uRepo.findAll(); + } + + public User findOneUser(Long id) { + return uRepo.findOne(id); + } + + // EVENT SERVICES + public List findAllEvents(){ + return eRepo.findAll(); + } + + public void saveEvent(Event e) { + eRepo.save(e); + } + + public Event findOneEvent(Long id) { + return eRepo.findOne(id); + } + + // ORGANIZATION SERVICES + public List findAllOrganizations(){ + return oRepo.findAll(); + } + + public void saveOrganization(Organization o) { + oRepo.save(o); + } + + public Organization findOneOrganization(Long id) { + return oRepo.findOne(id); + } + + // ISSUETAG SERVICES + public List findAllIssuetags(){ + return itRepo.findAll(); + } + + public void saveIssuetag(Issuetag it) { + itRepo.save(it); + } + + public Issuetag findOne(Long id) { + return itRepo.findOne(id); + } + + + + + +} \ No newline at end of file diff --git a/src/main/java/com/oen/prototype_2/validator/UserValidator.java b/src/main/java/com/oen/prototype_2/validator/UserValidator.java new file mode 100644 index 0000000..6d3398c --- /dev/null +++ b/src/main/java/com/oen/prototype_2/validator/UserValidator.java @@ -0,0 +1,39 @@ +package com.oen.prototype_2.validator; + +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +import com.oen.prototype_2.models.User; + +@Component + +public class UserValidator implements Validator{ + + @Override + + public boolean supports(Class clazz) { + + return User.class.equals(clazz); + + } + + @Override + + public void validate(Object object, Errors errors) { + + User user = (User) object; + + + + if (!user.getPasswordConfirmation().equals(user.getPassword())) { + + // 3 + + errors.rejectValue("passwordConfirmation", "Match"); + + } + + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..54e9ca5 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/oen_proto2 +spring.datasource.username=root +spring.datasource.password=root +spring.datasource.driver-class-name=com.mysql.jdbc.Driver +spring.jpa.hibernate.ddl-auto=update + +spring.mvc.view.prefix: /WEB-INF/ \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/about.jsp b/src/main/webapp/WEB-INF/about.jsp new file mode 100644 index 0000000..ba4bfdb --- /dev/null +++ b/src/main/webapp/WEB-INF/about.jsp @@ -0,0 +1,47 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + +User Profile + + +
+
+
+
+ + +
+
+
+

About EON

+
+ + +
+
+

Our goal is to become a central conduit for passionate individuals that want to become involved in their community

+
+
+
+

By invigorating the way Tulsa and the greater Oklahoma community approaches civic engagement, we can change the political atmosphere of Oklahoma through a comprehensive development strategy which includes fundraising, volunteerism, digital media, and partnerships with existing nonprofits.

+
+

Civic engagement culminates through voter education and we hope to act as a central location for non-partisan, up-to-date information on local and state elections and candidates.

+
+

+
+ + +
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/createEvent.jsp b/src/main/webapp/WEB-INF/createEvent.jsp new file mode 100644 index 0000000..42f8166 --- /dev/null +++ b/src/main/webapp/WEB-INF/createEvent.jsp @@ -0,0 +1,36 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + +Organization Creation + + +
+
+
+ +

+ Event Name: + +

+

+ Description (mandatory): + +

+ + +
+
+
+ + + +
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/createOrganization.jsp b/src/main/webapp/WEB-INF/createOrganization.jsp new file mode 100644 index 0000000..3736fc1 --- /dev/null +++ b/src/main/webapp/WEB-INF/createOrganization.jsp @@ -0,0 +1,39 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + +Organization Creation + + +
+
+
+ +

+ Organization Name: + +

+

+ Description (mandatory): + +

+

+ Location: + +

+ +
+
+
+ + + +
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/dashboard.jsp b/src/main/webapp/WEB-INF/dashboard.jsp new file mode 100644 index 0000000..6dea35e --- /dev/null +++ b/src/main/webapp/WEB-INF/dashboard.jsp @@ -0,0 +1,95 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + +User Profile + + +
+
+
+
+ + +
+
+
+

+
+ + +
+ +
+

Issue Areas

+
+
+

Education

+
+
+

Criminal Justice

+
+
+
+
+

Criminal Justice

+
+
+

Local Development

+
+
+
+
+

Healthcare

+
+
+

Legislative Advocacy

+
+
+
+ +
+
+

Upcoming Events

+ + + + + + + + + + + + + + + + +
NameDateLocation
+ + + + + + + Event Page +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/editProfile.jsp b/src/main/webapp/WEB-INF/editProfile.jsp new file mode 100644 index 0000000..e93a147 --- /dev/null +++ b/src/main/webapp/WEB-INF/editProfile.jsp @@ -0,0 +1,60 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + +Organization Creation + + +
+
+
+ + Current First Name : +

+ Change First Name To : + +

+
+ Current Last Name : +

+ Change Last Name To : + +

+
+ Current Zip Code : +

+ Change Zip Code To : + +

+
+ PASSWORD +

+ Change Password To : + +

+
+ Current Username : +

+ Change Username To : + +

+
+ + +
+
+
+ + + +
+
+
+ + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/eventpage.jsp b/src/main/webapp/WEB-INF/eventpage.jsp new file mode 100644 index 0000000..32e0ba2 --- /dev/null +++ b/src/main/webapp/WEB-INF/eventpage.jsp @@ -0,0 +1,44 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + +Event Page + + +
+
+
+
+ + +
+
+
+

+
+ + +
+
+

+ Description: +

+
+ Location: +

+
+ Started By: +

+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/login.jsp b/src/main/webapp/WEB-INF/login.jsp new file mode 100644 index 0000000..1f08e5a --- /dev/null +++ b/src/main/webapp/WEB-INF/login.jsp @@ -0,0 +1,80 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + + Login + + +
+ + + +
+

Register!

+ +

+ +

+ Email : + +

+

+ First Name : + +

+

+ Last Name : + +

+

+ Username : + +

+

+ Password : + +

+

+ Password Confirmation : + +

+ +
+ + + +

+ +
+
+ +

Login

+ +
+ + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/userprofile.jsp b/src/main/webapp/WEB-INF/userprofile.jsp new file mode 100644 index 0000000..328ea76 --- /dev/null +++ b/src/main/webapp/WEB-INF/userprofile.jsp @@ -0,0 +1,147 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + +User Profile + + +
+
+
+
+ + +
+
+
+

Hey !

+
+ +

+ +
+ +
+

Organizations Seeking Volunteers

+ + + + + + + + + + + + + + + +
NameHQUpcoming Events
+ + + + + + + +
+
+
+
+ + +

Pages I Admin

+ + + + + + + + + + + + + + + + + + +
NameHQTotal ActivistsCreate an Event
+ + + + + + + + + + + + + + + - + + + + + + Start + + +
+
+
+
+
+ + + +
+

Upcoming Events

+ + + + + + + + + + + + + + + +
NameDateLocation
+ + + + + +
+
+ + + +
+ + \ No newline at end of file diff --git a/src/test/java/com/oen/prototype_2/OklahomaEngagementNetworkApplicationTests.java b/src/test/java/com/oen/prototype_2/OklahomaEngagementNetworkApplicationTests.java new file mode 100644 index 0000000..4d75ba8 --- /dev/null +++ b/src/test/java/com/oen/prototype_2/OklahomaEngagementNetworkApplicationTests.java @@ -0,0 +1,16 @@ +package com.oen.prototype_2; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class OklahomaEngagementNetworkApplicationTests { + + @Test + public void contextLoads() { + } + +}