Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions quiz.json
Original file line number Diff line number Diff line change
@@ -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"}]
1 change: 1 addition & 0 deletions recentquotes.json
Original file line number Diff line number Diff line change
@@ -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/"}
31 changes: 29 additions & 2 deletions src/main/java/com/example/init/InitApplication.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/example/init/controllers/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ public class Home {
public String home() {
return "home";
}

@GetMapping("/index")
public String index() {
return "index";
}

}
106 changes: 106 additions & 0 deletions src/main/java/com/example/init/controllers/User.java
Original file line number Diff line number Diff line change
@@ -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<Coders> 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<Coders> myfollowers = feed.getFollowers();
model.addAttribute("allfollowers", myfollowers);
return "feed";
}
}
Loading