diff --git a/api.json b/api.json new file mode 100644 index 0000000..fa9b858 --- /dev/null +++ b/api.json @@ -0,0 +1,98 @@ +[ + { + "id": 849, + "question": "How to remove the docker container with container id mentioned in the command.", + "description": null, + "answers": { + "answer_a": "$ docker rm -rf 9b6343d3b5a0", + "answer_b": "$ docker -rm rf 9b6343d3b5a0", + "answer_c": "$ docker rm 9b6343d3b5a0", + "answer_d": null, + "answer_e": null, + "answer_f": null + }, + "multiple_correct_answers": "false", + "correct_answers": { + "answer_a_correct": "false", + "answer_b_correct": "false", + "answer_c_correct": "true", + "answer_d_correct": "false", + "answer_e_correct": "false", + "answer_f_correct": "false" + }, + "correct_answer": "answer_a", + "explanation": null, + "tip": null, + "tags": [ + { + "name": "Docker" + } + ], + "category": "Docker", + "difficulty": "Easy" + }, + { + "id": 26, + "question": "What is a daemon?", + "description": null, + "answers": { + "answer_a": "It is a generic name for e-mail servers on Linux. The most famous one is mailer-daemon", + "answer_b": "It is a program that keeps running on the background after it is called, answering to requests done by users and other programs.", + "answer_c": "It is an antivirus for Linux.", + "answer_d": "It is the generic name for any Linux server.", + "answer_e": null, + "answer_f": null + }, + "multiple_correct_answers": "false", + "correct_answers": { + "answer_a_correct": "false", + "answer_b_correct": "true", + "answer_c_correct": "false", + "answer_d_correct": "false", + "answer_e_correct": "false", + "answer_f_correct": "false" + }, + "correct_answer": "answer_b", + "explanation": null, + "tip": null, + "tags": [ + { + "name": "Linux" + } + ], + "category": "Linux", + "difficulty": "Medium" + }, + { + "id": 627, + "question": "How can we set infinite execution time for a PHP script?", + "description": null, + "answers": { + "answer_a": "Add set_time_limit() at the beginning of a script", + "answer_b": "Add set_time_limit(infinity) at the beginning of a script", + "answer_c": "Add set_time_limit(0) at the beginning of a script", + "answer_d": null, + "answer_e": null, + "answer_f": null + }, + "multiple_correct_answers": "false", + "correct_answers": { + "answer_a_correct": "false", + "answer_b_correct": "false", + "answer_c_correct": "true", + "answer_d_correct": "false", + "answer_e_correct": "false", + "answer_f_correct": "false" + }, + "correct_answer": "answer_a", + "explanation": null, + "tip": null, + "tags": [ + { + "name": "PHP" + } + ], + "category": "Code", + "difficulty": "Medium" + } + ] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 71840fc..132b0e6 100644 --- a/build.gradle +++ b/build.gradle @@ -13,16 +13,17 @@ repositories { } dependencies { - // implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - // implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-websocket' - // implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'org.postgresql:postgresql' testImplementation 'org.springframework.boot:spring-boot-starter-test' - // testImplementation 'org.springframework.security:spring-security-test' + implementation 'com.google.code.gson:gson:2.8.8' + testImplementation 'org.springframework.security:spring-security-test' } test { diff --git a/quiz.json b/quiz.json new file mode 100644 index 0000000..2f5acc5 --- /dev/null +++ b/quiz.json @@ -0,0 +1 @@ +[{"id":711,"question":"Are arrays supported in shell scripts?","description":null,"answers":{"answer_a":"True","answer_b":"False","answer_c":"Yes but only under certain conditions","answer_d":null,"answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"true","answer_b_correct":"false","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":null,"explanation":null,"tip":null,"tags":[{"name":"BASH"},{"name":"Linux"}],"category":"Linux","difficulty":"Easy"},{"id":943,"question":"What does PVC stand for?","description":null,"answers":{"answer_a":"Pod Volume Claim","answer_b":"Persistent Volume Container","answer_c":"Persistent Volume Claim","answer_d":"Pod Volume Container","answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"false","answer_c_correct":"true","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":null,"explanation":null,"tip":null,"tags":[{"name":"Docker"}],"category":"Docker","difficulty":"Medium"},{"id":339,"question":"Which of the following are not Numeric column types?","description":null,"answers":{"answer_a":"BIGINT","answer_b":"LARGEINT","answer_c":"SMALLINT","answer_d":"DOUBLE","answer_e":"DECIMAL","answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"true","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":"answer_a","explanation":null,"tip":null,"tags":[{"name":"MySQL"}],"category":"SQL","difficulty":"Hard"},{"id":662,"question":"Which command can give first found difference between two file after comparing?","description":null,"answers":{"answer_a":"diff","answer_b":"cmp","answer_c":"Common","answer_d":"stat","answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"true","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":"answer_a","explanation":null,"tip":null,"tags":[{"name":"BASH"}],"category":"Linux","difficulty":"Easy"},{"id":548,"question":"Which of the following is used to add multiple line comments in PHP ?","description":null,"answers":{"answer_a":"\/\/","answer_b":"\/* *\/","answer_c":"{{ }}","answer_d":"{\/ \\}","answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"true","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":"answer_a","explanation":null,"tip":null,"tags":[{"name":"HTML"}],"category":"Code","difficulty":"Medium"}][{"id":711,"question":"Are arrays supported in shell scripts?","description":null,"answers":{"answer_a":"True","answer_b":"False","answer_c":"Yes but only under certain conditions","answer_d":null,"answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"true","answer_b_correct":"false","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":null,"explanation":null,"tip":null,"tags":[{"name":"BASH"},{"name":"Linux"}],"category":"Linux","difficulty":"Easy"},{"id":943,"question":"What does PVC stand for?","description":null,"answers":{"answer_a":"Pod Volume Claim","answer_b":"Persistent Volume Container","answer_c":"Persistent Volume Claim","answer_d":"Pod Volume Container","answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"false","answer_c_correct":"true","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":null,"explanation":null,"tip":null,"tags":[{"name":"Docker"}],"category":"Docker","difficulty":"Medium"},{"id":339,"question":"Which of the following are not Numeric column types?","description":null,"answers":{"answer_a":"BIGINT","answer_b":"LARGEINT","answer_c":"SMALLINT","answer_d":"DOUBLE","answer_e":"DECIMAL","answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"true","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":"answer_a","explanation":null,"tip":null,"tags":[{"name":"MySQL"}],"category":"SQL","difficulty":"Hard"},{"id":662,"question":"Which command can give first found difference between two file after comparing?","description":null,"answers":{"answer_a":"diff","answer_b":"cmp","answer_c":"Common","answer_d":"stat","answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"true","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":"answer_a","explanation":null,"tip":null,"tags":[{"name":"BASH"}],"category":"Linux","difficulty":"Easy"},{"id":548,"question":"Which of the following is used to add multiple line comments in PHP ?","description":null,"answers":{"answer_a":"\/\/","answer_b":"\/* *\/","answer_c":"{{ }}","answer_d":"{\/ \\}","answer_e":null,"answer_f":null},"multiple_correct_answers":"false","correct_answers":{"answer_a_correct":"false","answer_b_correct":"true","answer_c_correct":"false","answer_d_correct":"false","answer_e_correct":"false","answer_f_correct":"false"},"correct_answer":"answer_a","explanation":null,"tip":null,"tags":[{"name":"HTML"}],"category":"Code","difficulty":"Medium"}] \ No newline at end of file diff --git a/recentquotes.json b/recentquotes.json new file mode 100644 index 0000000..fa6c1bc --- /dev/null +++ b/recentquotes.json @@ -0,0 +1 @@ +{"quoteText":"A lot of people give up just before theyre about to make it. You know you never know when that next obstacle is going to be the last one. ", "quoteAuthor":"Chuck Norris", "senderName":"", "senderLink":"", "quoteLink":"http://forismatic.com/en/2bc6cf0fd5/"} \ No newline at end of file diff --git a/src/main/java/com/example/init/InitApplication.java b/src/main/java/com/example/init/InitApplication.java index 365f755..b97166e 100644 --- a/src/main/java/com/example/init/InitApplication.java +++ b/src/main/java/com/example/init/InitApplication.java @@ -1,13 +1,40 @@ package com.example.init; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.io.*; +import java.lang.reflect.Type; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; +import java.util.Set; + @SpringBootApplication public class InitApplication { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { SpringApplication.run(InitApplication.class, args); - } +// StringBuilder createdLine = new StringBuilder(); +// String url = "https://quizapi.io/api/v1/questions?apiKey=phkL2Z69NDCrImLlfnLoElQkoF3StoJlQrAeKvkf&limit=5&css"; +// HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); +// +// connection.setConnectTimeout(5000); +// connection.setReadTimeout(5000); +// +// InputStreamReader inputStreamReader = new InputStreamReader(connection.getInputStream()); +// BufferedReader bufferedReader = new BufferedReader(inputStreamReader); +// +// String data = bufferedReader.readLine(); +// createdLine = new StringBuilder(data); +// System.out.println(data); +// createdLine.append(data); +// bufferedReader.close(); +// FileWriter fileToWrite = new FileWriter("quiz.json"); +// fileToWrite.write(createdLine.toString()); +// fileToWrite.close(); + } } diff --git a/src/main/java/com/example/init/controllers/Home.java b/src/main/java/com/example/init/controllers/Home.java index 6adc840..b34f5e3 100644 --- a/src/main/java/com/example/init/controllers/Home.java +++ b/src/main/java/com/example/init/controllers/Home.java @@ -10,4 +10,10 @@ public class Home { public String home() { return "home"; } + + @GetMapping("/index") + public String index() { + return "index"; + } + } diff --git a/src/main/java/com/example/init/controllers/User.java b/src/main/java/com/example/init/controllers/User.java new file mode 100644 index 0000000..dbc111d --- /dev/null +++ b/src/main/java/com/example/init/controllers/User.java @@ -0,0 +1,106 @@ +package com.example.init.controllers; + +import com.example.init.models.Coders; +import com.example.init.models.Post; +import com.example.init.repositories.CodersRepository; +import com.example.init.repositories.ContentRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.view.RedirectView; + +import java.security.Principal; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +@Controller +public class User { + + @Autowired + BCryptPasswordEncoder bCryptPasswordEncoder; + + @Autowired + CodersRepository codersRepository; + + @Autowired + ContentRepository contentRepository; + + @GetMapping("/signup") + public String getSignUpPage() { + return "signup"; + } + + @GetMapping("/login") + public String getSignInPage() { + return "login"; + } + + @PostMapping("/signup") + public RedirectView attemptSignUp(@ModelAttribute Coders user) { + Coders newUser = new Coders(user.getEmail(), user.getUsername(), + bCryptPasswordEncoder.encode(user.getPassword()), user.getFirstName(), user.getLastName(), + user.getDateOfBirth(), user.getBio()); + codersRepository.save(newUser); + Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>()); + SecurityContextHolder.getContext().setAuthentication(authentication); + return new RedirectView("/login"); + } + + @PostMapping("/login") + public RedirectView loginResponse(@ModelAttribute Coders user, Model model) { + model.addAttribute("username", codersRepository.findByUsername(user.getUsername())); + return new RedirectView("profile"); + } + + @GetMapping("/profile") + public String getUserProfile(Principal principal, Model model) { + Coders user = codersRepository.findByUsername(principal.getName()); + model.addAttribute("username", principal.getName()); + model.addAttribute("userProfile", user); + return "profile"; + } + + @PostMapping("/addPost") + public RedirectView addPost(Principal principle, String body) { + Coders newUser = codersRepository.findByUsername(principle.getName()); + Post post = new Post(newUser, body); + contentRepository.save(post); + return new RedirectView("/profile"); + } + + @GetMapping("/users") + public String getUsers(Model model, Principal principal) { + List users = codersRepository.findAll(); + model.addAttribute("allusers", users); + Coders user = codersRepository.findByUsername(principal.getName()); + model.addAttribute("username", user.getUsername()); + return "users"; + } + + + @PostMapping("/follow") + public RedirectView followUser(@AuthenticationPrincipal Coders user, @RequestParam Long id) { + Coders feed = codersRepository.findByUsername(user.getUsername()); + Coders follow = codersRepository.findUserById(id); + feed.getFollowers().add(follow); + codersRepository.save(feed); + return new RedirectView("/feed"); + } + + @GetMapping("/feed") + public String getUsersInfo(@AuthenticationPrincipal Coders user, Model model) { + model.addAttribute("username", user.getUsername()); + Coders feed = codersRepository.findByUsername(user.getUsername()); + List myfollowers = feed.getFollowers(); + model.addAttribute("allfollowers", myfollowers); + return "feed"; + } +} diff --git a/src/main/java/com/example/init/models/Coders.java b/src/main/java/com/example/init/models/Coders.java new file mode 100644 index 0000000..17930a5 --- /dev/null +++ b/src/main/java/com/example/init/models/Coders.java @@ -0,0 +1,171 @@ +package com.example.init.models; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import javax.persistence.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Entity +public class Coders implements UserDetails { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(unique = true) + private String email; + + @Column(unique = true) + private String username; + private String password; + private String firstName; + private String lastName; + private String dateOfBirth; + private String bio; + + @OneToMany(mappedBy = "applicationUser", fetch = FetchType.EAGER) + private List posts; + + @ManyToMany(cascade = { CascadeType.ALL }, fetch=FetchType.EAGER) + @JoinTable(name = "follower_follower", joinColumns = @JoinColumn(name = "from_id"), inverseJoinColumns = @JoinColumn(name = "to_id")) + List followers = new ArrayList<>(); + @ManyToMany(mappedBy = "followers", fetch=FetchType.EAGER) + List following = new ArrayList<>(); + + public Coders() { + } + + + public Coders(String email, String username, String password, String firstName, String lastName, String dateOfBirth, + String bio) { + this.email = email; + this.username = username; + this.password = password; + this.firstName = firstName; + this.lastName = lastName; + this.dateOfBirth = dateOfBirth; + this.bio = bio; + } + + @Override + public boolean isAccountNonExpired() { + return false; + } + + @Override + public boolean isAccountNonLocked() { + return false; + } + + @Override + public boolean isCredentialsNonExpired() { + return false; + } + + @Override + public boolean isEnabled() { + return false; + } + + public void setUsername(String username) { + this.username = username; + } + + @Override + public Collection getAuthorities() { + return null; + } + + 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; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getDateOfBirth() { + return dateOfBirth; + } + + public void setDateOfBirth(String dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + + public String getBio() { + return bio; + } + + public void setBio(String bio) { + this.bio = bio; + } + + public List getPosts() { + return posts; + } + + public void setPosts(List posts) { + this.posts = posts; + } + + public List getFollowers() { + return this.followers; + } + + public void setFollowers(List followers) { + this.followers = followers; + } + + public List getFollowing() { + return this.following; + } + + public void setFollowing(List following) { + this.following = following; + } + + public void addFollower(Coders follower) { + this.followers.add(follower); + } +} diff --git a/src/main/java/com/example/init/models/Post.java b/src/main/java/com/example/init/models/Post.java new file mode 100644 index 0000000..f8722c7 --- /dev/null +++ b/src/main/java/com/example/init/models/Post.java @@ -0,0 +1,67 @@ +package com.example.init.models; + +import javax.persistence.*; + +import java.sql.Timestamp; +import java.text.SimpleDateFormat; + +@Entity +public class Post { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @ManyToOne + @JoinColumn(name = "application_user_id") + private Coders applicationUser; + + private String body; + + private String createdAt; + + public Post() { + } + + public Post(Coders applicationUser, String body) { + this.applicationUser = applicationUser; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm"); + this.createdAt = sdf.format(new Timestamp(System.currentTimeMillis()).getTime()); + + this.body = body; + + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Coders getApplicationUser() { + return applicationUser; + } + + public void setApplicationUser(Coders applicationUser) { + this.applicationUser = applicationUser; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public String getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + +} diff --git a/src/main/java/com/example/init/repositories/CodersRepository.java b/src/main/java/com/example/init/repositories/CodersRepository.java new file mode 100644 index 0000000..ff311e5 --- /dev/null +++ b/src/main/java/com/example/init/repositories/CodersRepository.java @@ -0,0 +1,12 @@ +package com.example.init.repositories; + +import com.example.init.models.Coders; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CodersRepository extends JpaRepository { + public Coders findByUsername(String username); + public Coders findUserById(long id); + +} \ No newline at end of file diff --git a/src/main/java/com/example/init/repositories/ContentRepository.java b/src/main/java/com/example/init/repositories/ContentRepository.java new file mode 100644 index 0000000..5ed3ccd --- /dev/null +++ b/src/main/java/com/example/init/repositories/ContentRepository.java @@ -0,0 +1,9 @@ +package com.example.init.repositories; + +import com.example.init.models.Post; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ContentRepository extends JpaRepository { +} diff --git a/src/main/java/com/example/init/security/UserDetailsServiceImpl.java b/src/main/java/com/example/init/security/UserDetailsServiceImpl.java new file mode 100644 index 0000000..9c2216e --- /dev/null +++ b/src/main/java/com/example/init/security/UserDetailsServiceImpl.java @@ -0,0 +1,25 @@ +package com.example.init.security; + +import com.example.init.models.Coders; +import com.example.init.repositories.CodersRepository; +import org.springframework.beans.factory.annotation.Autowired; +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; + +@Service +public class UserDetailsServiceImpl implements UserDetailsService { + + @Autowired + CodersRepository codersRepository; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + Coders coders = codersRepository.findByUsername(username); + if (coders == null) { + throw new UsernameNotFoundException((username + " not found!")); + } + return coders; + } +} diff --git a/src/main/java/com/example/init/security/WebSecurityConfig.java b/src/main/java/com/example/init/security/WebSecurityConfig.java new file mode 100644 index 0000000..f41bb01 --- /dev/null +++ b/src/main/java/com/example/init/security/WebSecurityConfig.java @@ -0,0 +1,58 @@ +package com.example.init.security; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +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.crypto.bcrypt.BCryptPasswordEncoder; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + @Autowired + UserDetailsServiceImpl userDetailsService; + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .cors() + .disable(). + csrf() + .disable() + .authorizeRequests() + .antMatchers( "/login", "/signup","/") + .permitAll().antMatchers("/adminpanel") + .hasAuthority("ROLE_ADMIN") + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login") + .usernameParameter("email") + .permitAll() + .loginProcessingUrl("/perform_login") + .defaultSuccessUrl("/", true) + .failureUrl("/error") + .and() + .logout() + .logoutUrl("/perform_logout"); + } + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f03a366..1834ae5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,21 @@ -spring.sql.init.platform=postgres -spring.datasource.url=jdbc:postgresql://localhost:5432/coders -spring.datasource.username=abdelqader -spring.datasource.password=0000 -spring.jpa.database=postgresql -spring.jpa.generate-ddl=true -spring.jpa.hibernate.ddl-auto=update +server.port=8081 + +# Connect to the Database +## default connection pool +spring.datasource.hikari.connectionTimeout=20000 +spring.datasource.hikari.maximumPoolSize=5 +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true +## PostgreSQL +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username= postgres +spring.datasource.password=1234 + +spring.jpa.show-sql=true +spring.jpa.generate-ddl=false +spring.jpa.open-in-view=false +spring.jpa.properties.hibernate.show_sql=true +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.type=trace + +#drop n create table again, good for testing, comment this in production +spring.jpa.hibernate.ddl-auto=create \ No newline at end of file diff --git a/src/main/resources/templates/feed.html b/src/main/resources/templates/feed.html new file mode 100644 index 0000000..04d34b3 --- /dev/null +++ b/src/main/resources/templates/feed.html @@ -0,0 +1,32 @@ + + + + + Feed page + + +
+

Feed Posts

+
+
+
+
Username:
+



+ + + + +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 033f5e1..6b510d5 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -8,5 +8,13 @@

Hello World

+ diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html new file mode 100644 index 0000000..1fbc38b --- /dev/null +++ b/src/main/resources/templates/login.html @@ -0,0 +1,29 @@ + + + + + login + + + +
+ +
+ Invalid username and password. +
+
+ You have been logged out. +
+ +
+ + +
+
+ + +
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/profile.html b/src/main/resources/templates/profile.html new file mode 100644 index 0000000..48d79a4 --- /dev/null +++ b/src/main/resources/templates/profile.html @@ -0,0 +1,48 @@ + + + + + user profile + + + +
+ ProfilePicture +
+ +

+

+

+

+
+ +
+
+ +
+
+
+ + +
+ +
+
+
+ +
+
+ +Posts + +
+
+
+

+

+
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/signup.html b/src/main/resources/templates/signup.html new file mode 100644 index 0000000..fabf8b3 --- /dev/null +++ b/src/main/resources/templates/signup.html @@ -0,0 +1,52 @@ + + + + + signup + + + +
+ Sign up +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + diff --git a/src/main/resources/templates/users.html b/src/main/resources/templates/users.html new file mode 100644 index 0000000..df39741 --- /dev/null +++ b/src/main/resources/templates/users.html @@ -0,0 +1,46 @@ + + + + + + Suggest Friends + + + +
+

People You May Know

+
+
    + +
  • +
  • +
  • + + + + +
    + + +
    + +
+
+ +