#dev-general
1 messages ยท Page 72 of 1
thanks i think i sorted it lol
@heady birch whats something like a UserRepository in spring?
So, this is how I understnad it, idk if its right,
1 - The controller decides what happens when you go to the url
2 - The UserDto like puts it on the database?(Not certain about that one)
idk if thats right lol
@obtuse gale read up on the repository pattern.
where abouts would i do that?
UserRepository puts it in the database
deletes stuff and finds stuff
UserDto represents the html <form>
yeah 2
and like whats the difference
User represents a user in the database
UserRepository handles getting User and putting a User in the database
UserDto will be used by the controller and your service
Service will check that UserDto password matches e.g
Edit: or form validation
And Service will create a new User based on the details of the UserDto
And Tell UserRepository.save(User)
ah
what are some like standard package names? Idk what to call packages for these kinda things lol
some peopl group like
repository controller service config dto
I usually do it like this
user - would have UserRepository User UserDto e.g
ah alright
some can help me?
im trying to create /kits gui menu which can provide player kits in click on gui item
i can do it with deluxemenus?
What does adding an attribute to a model do niall? I keep making the mistake of just typing stuff out without knowing what it does
How do I clone from gh from a certain commit?
or this I guess https://stackoverflow.com/a/3555202
Hello, is there someone who could give me a โsimpleโ plugin? i define simple as, made in IntelliJ, nothing special like a shorter version of worldedit or a better version of essentials
what for
How is that "simple" kek
i dunno
there are lots of open source plugins out there
where ๐
What does adding an attribute to a model do niall? I keep making the mistake of just typing stuff out without knowing what it does
@obtuse gale It makes it accessible to Thymeleaf
So if I have object:
class Car {
var name: String
var manufacturer: Manufacturer
}
class Manufacturer {
var name: String
}
model.addAtribute("car", Car())
Why are vectors so annoying, I'm just trying to minus vec1 from vec2 and i have a 139MB error log lol
Car Name: <span th:text="${car.name}"></span>
Car Manufacturer: <span th:text="${car.manufacturer.name}"></span>
Gaby, I'm so confused lmao
I love kotlin
@topaz bay Thank you, I also have a question
Obviously companion object is useful for putting static variables
It looks as if theres no equivalent to the static block however
static {
//..
}```
init
niall what would go in the User class? not the UserDTO class, just the USer class
companion object
{
init
{
// code here
}
}
Yeah
what would that look like
Of course you only really want what you need in the database
Maybe start with just id, email, username, password
yea, so how come like id and password have @Column, but email doesnt
And whats manytomany and jointable
@distant sun Your existence is wrong.
@topaz bay WRONG
You can if you want annotate them all with Column
Sx knows what's up lmao
They are only doing it to specify specific things (like the length, or wether the column has to be unique)
So they should really have
wdym unique?
@Column(unique = true)
private String email;
the column contents has to be unique
unique as in no two User can have the same email address
ah
I think I followed this tutorial and some users would spam the register button and end up with 3 accounts
migrations
No the only thing you need to make sure exists is the database
And it creates the tables automatically from your User class
orms are pretty neat rarely use them in java though tbh
not that I actually do lots of java anyway
Yeah they are very good
Hey there! I have now finished learning quite a bit about java and I would now like to move on to minecraft plugin development. What is a good place to start learning + should I use craftbukkit or spigot?
depends on your use case
If you wanna do big, maybe commercial plugins, there's probably no way around spigot
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
The wiki is a good place to start
Is spigot better the bukkit?
@nocturne dock should be ye
What is the difference?
spigot is somewhat of the continuation of bukkit
user paper tho lol
It uses bukkit as its base and was originally a separate fork, but now bukkit is abandoned afaik
Niall, I see in the github thingy u linked it had
private Collection<Role> roles;
I get the following if i do that
'Basic' attribute type should not be a container
okay! Is there some good way of learning everything in Spigot without just browsing the forums?
javadocs are always handy
@obtuse gale you will need @ElementCollection or @OneToMany I believe
although spigot's are pretty shit
^
Hm, what do those do though?
What is paper?
@OneToMany makes a relationship - one user will have many roles for example
A fork of spigot
Is paper better then spigot?
Yes
ah
Should I learn that?
the API isn't very different
if you know one you pretty much know all of the other
Paper mostly improves things under the hood
so I can just start with spigot
yep
oke
'One To Many' attribute value type should not be 'Role'
Is Role an @Entity?
oh
Well relationships are between entities so
you also probably want a bidirectional relationship, so if Role has anything referencing a User or whatever it is, give that @ManyToOne
hm
see this many to one and many to many stuff is the bit that confuses me lol
What does it effect in the database?
It's confusing at first
this is why diagrams and things exist
Basically it makes foreign keys to map to the other entity
wat
I would imagine if you actually know sql it would make sense
lol
So something like:
users:
| Id | Name | Age |
| 1 | Dave | 39 |
Will also have
user_roles:
| User_id | role_id |
| 1 (Dave) | 1 (Admin) |
There would also be a Roles table but I'm on mobile and last
Lazy*
ive currently got it imported from
package java.util;
wait
no i dont lol
javax.management.relation
But with @OneToMany i get One To Many' attribute value type should not be 'Role
oh yeah ManyToMany mb
Integer id,
String name
pretty much
ah ok, and how do roles work? Like is it so i can have an admin only page and stuff?
Basically yeah
I still get the same thign
Have you made sure your importing your Role class
and your Role class is anottated with @Entity
ah
that was it
forogt @entity
in the guide they use java private static List<GrantedAuthority> getAuthorities(List<String> roles){ List<GrantedAuthority> authorities = new ArrayList<>(); for(String role : roles){ authorities.add(new SimpleGrantedAuthority(role)); } return authorities; }
That takes in a list of strings, and they use user.getRoles, for me user.getroles returns a collection of roles
I could adjust it to this maybe
private static List<GrantedAuthority> getAuthorities(Collection<Role> roles){
List<GrantedAuthority> authorities = new ArrayList<>();
for(Role role : roles){
authorities.add(new SimpleGrantedAuthority(role.getName()));
}
return authorities;
}```
Yep thats correct
so tempted to throw a stream there ๐ฎ
roles.stream().map(role -> new SimpleGrantedAuthority(role.getName())).collect(Collectors.toList())
Anything else.. or have you already got stuff in there?
nothing atm
Are you using mysql?
I think s olol
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.url=jdbc:mysql://HOSTNAME:3306/DATABASENAME?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=USERNAME
spring.datasource.password=PASSWORD```
Make sure you do it on empty database
You might not need line 2 really.. but I had some issue and that fixed it
yea, do i need to run something like xxamp in the background or whatever? Or is the database hosted like with intellij
You will need to host it
alrgiht
So yeah xammp would work
Does like spring have some sort of default login thing? I found it on google yesterday when i was looking up registration form... now ive started my app, im like stuck at this login page that i didnt make lol
yeah spring security makes one by default
yea lol how tf do i get rid of it lol
I think i got rid of it
But now i always get
welp i got it to somewhat work
I got the form to show up, but when i click submit the page just refreshes and i go to a page that says tjhe error type is Forbidden
Yeah so you should have an error come up in the run window in IDEA
na, that errors old, now when i complete the form it takes me to localhost:8080 and gives this
/user/register
ok
Could you send your template for /user/register? (html file)
Most likely your form doesnt submit to correct location
Or you need @PostMapping instead of @GetMapping when processing form
=paste
Please use a paste service to share configs, errors, code and long logs.
โข HelpChat Paste
Can you send the controller class?
Ok so now you will definatley get an error in the console
look carefully for the useful part
If you cant find it paste it here
ah an npe
at com.aj.website.service.UserService.emailExists(UserService.java:27) ~[classes/:na]
at com.aj.website.service.UserService.registerNewUserAccount(UserService.java:18) ~[classes/:na]
at com.aj.website.controller.RegistrationController.registerUserAccount(RegistrationController.java:37) ~[classes/:na]```
whats in UserService:27
return userRepository.getUserByEmail(email) != null;
is your userRepository autowired?
userDto.getEmail())
@Transactional
@Override
public User registerNewUserAccount(UserDto userDto) throws UserAlreadyExistsException {
if(emailExists(userDto.getEmail())) throw new UserAlreadyExistsException("There is already a valid user with the email: " + userDto.getEmail());
User user = new User();
user.setFirstName(userDto.getFirstName());
user.setUsername(userDto.getUsername());
user.setEmail(userDto.getEmail());
user.setPassword(userDto.getPassword());
return userRepository.save(user);
}
private boolean emailExists(String email){
return userRepository.getUserByEmail(email) != null;
}
}
Let's see UserDto
Thats odd
UserDto could be null?
I assume you have in one of your controller methods:
@Valid UserDto user
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid UserDto userDto, HttpServletRequest request, Errors errors, ModelAndView mav){
yeah looks right
alright
bruh im lost lol
email isnt null, so like what could it be, since thats where the NPE is from
return userRepository.getUserByEmail(email) != null; thats the excact line thats giving it :/
Maybe try replace method="POST" with th:method="POST"
how do u reset ezprestige data xD?
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid UserDto userDto, HttpServletRequest request, Errors errors, ModelAndView mav){
And this method is annotated with @PostMapping?
ye
Ok
it will be as simple are removing the data files it creates @obtuse gale
i don't see how that's difficult
theres none though
there has to be
only config & prestiges.yml
is it using a database?
Ah
Your service should be autowired
Make sure you annotate UserService with @Service
Then @Autowired UserService userService; in your controller
ah oki
When you do new UserService() spring cannot autowire the repository
So UserRepository will be null
In a spring application you don't do new on any main components
It creates them automatically when they are annotated with @Service @Controller e.g
now, if i wanna make a page that only people logged in can access how would i do so?
You would create another template file and controller method
Then restricting access is down to the security config
also i just realised i dont even have alogin form lol
Yeah the login is not as hard
You only need to write the form, theres no DTO's involved
ah
So do i just need to like
Get the values from the form, and check if they are the right one?
First of all create a form
<head></head>
<body>
<h1>Login</h1>
<form action="/user/login" method='POST'>
<table>
<tr>
<td>Username:</td>
<td><input type='text' name='username' value=''></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>```
yea
In your security config add a matcher
.antMatcher("/user/login").permitAll()
I think it's permitAll
Yes
did i do this right?java @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/user/registration").permitAll() .and().authorizeRequests().antMatchers("/user/login").permitAll(); }
i feel like i did something wrong lol
.antMatchers("/...").permitAll()
.antMatchers("/...").permitAll()
.anyRequest().authenticated()```
It wont let me call .antMatchers twice
Edited it, that should work
ye
yeah
We need to make some beans in the same class
First of all, the password encoderjava @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); }
do i make a new class for this?
Security Config?
yeah
Now an authentication provider
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider auth = new DaoAuthenticationProvider();
auth.setUserDetailsService(userService);
auth.setPasswordEncoder(passwordEncoder());
return auth;
}```
This tells spring to use our UserService (you will need to autowire that into SecurityConfig) for authentication
UserDetailsService
Provided:
UserService``` on
auth.setUserDetailsService(userService);
I think we did do this earlier
but make sure your UserService interface extends UserDetailsService
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}```
Make spring use our DaoAuthenticationProvider
That goes in security config as well
yep
Now the cool part
Add this to the end of your antMatchers bit...
.and()
.formLogin()
.loginPage("/user/login")
.passwordParameter("password")
.usernameParameter("username")
.loginProcessingUrl("/user/login")
.failureUrl("/login?error=true")
Cant remember if the processing url has to be different..
But if it does id just make it /user/login/p
and then the form action="/user/login/p"
so now ive got
http.authorizeRequests()
.antMatchers("/user/registration").permitAll()
.antMatchers("/user/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.passwordParameter("password")
.usernameParameter("username")
.loginProcessingUrl("/user/login")
.failureUrl("/login?error=true");```
alright
Wait cos i extended UserDetailsService my UserService class now wants me to implement get user by uysername or something
and it wants to return a UserDetails
yeah
how do i return userdetails?
Lol
:)))
So I do this
@obtuse gale Did we do this?
You were talking about Authorities and stuff
And you had that code
Hey guys, I'm trying to check if a player has a bed location set
if (p.getBedLocation() == null) {
Funnily enough I used this null check to prevent errors but it's throwing an error because it is null
Does anyone know how I can fix this?
if that's throwing an NPE then p is null
@ocean quartz can I put subcommands in different classes for ur command framework?
Just trying out ur command framework for a client plugin
After that I'm prolly gonna make my own framework
Yeah
How do I do it then
As long as they have the same @Command("") they are part of the same
All subclasses will be linked
Well
/sc is to toggle
You can leave and join
And if you type in /sc other players won't see it
Unless they have the permission
xD
Wait lemme find chat channels
I don't maintain the plugin anymore because its merged into my chat plugin but still available
@signal tinsel Checkout my ploogin if you wanna see how to use Matt's framework, it's nothing fancy but it uses commands and subcommands, fairly organised
Haters gonna hate
Honestly
I might add /premiumchat debug
Which upload all configuration and data files to hastebin together with things like all installed placeholder expansions
Would make it easier
To provide support atleast
@heady birch yea i got that working, now if i enter the same email I just want to get like an error, it juts reloads to this
It couldn't find the template
what template is it looking for lol
Do you throw an exception in UserService when they already have an email
And catch it in the controller
I usually catch the exception then add a message using model.addAttribute("error", "This email address is already in use")
yea thats what i did
@Autowired
private UserService userService;
@PostMapping("/user/registration")
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid UserDto userDto, HttpServletRequest request, Errors errors, ModelAndView mav){
try{
User register = userService.registerNewUserAccount(userDto);
} catch (UserAlreadyExistsException e) {
mav.addObject("message","An account already exists with this email/username");
return mav;
}
return new ModelAndView("successRegister", "user", userDto);
}```
Oh you return mav
Try returning new ModelAndView("(your template)", "message", "An account with this email already exists");
your template would be the normal registration one, not the successRegister one
Is there a Maven repo for the DeluxeChat API?
Am I allowed to distribute the JAR with the source code for others though? Presumably that'd not be allowed for a premium plugin.
You should only use it to reference the methods, and not actually shade the plugin in
Yup but if the plugin using those references is open source, others won't have those references if they want to compile the plugin's source code themselves.
Yeah, not gonna happen, oh well, makes the support choice easy.
You using maven or gradle or neither?
throw it in your local repo and it'll be easy, ofc those who want to compile it will also have to do that themselves
Know how to local repo - but asking people to buy DeluxeChat to compile the plugin is not going to happen.
softdepend for additional support - so will remove the softdepend and additional support
Well I mean it's softdepend so you're not relying on dchat
Just have all the dchat methods in the class which they can remove if they aren't using it
No worries, have saved them the effort of removing it themselves.
wut
Someone that knows C++?
so how do i make a menu?
lol
how would i make a kitpvp menu?
do you know Java?
ive heard he's a cool guy, what about him
jokes
Ahaha right? Who uses kotlin?
Real devs use CSS for minecraft plugins ๐
@remote goblet i thought real devs used skript ;)
I hate skript btw
I downloaded the skript repo printed out every file and shredded it
.onEnable {
// I dont know css
}
that sounds like a waste of paper
gross i forget i dont have nitro
on this server
:(
Someone with 70k followers just followed me on twitter wtf
.onEnable #server{
registerListeners: url("com.aj3douglas.plugin.listeners.idk");
}
``` idk css lol
What are you trying to do? xD
if its for dev related support #development
ight so im trying to decompile superboosters to add tokenenchat support
ok
could you help me in #development ?
MySQL sounds like al ot of work to learn
Heard clip loves mysql
@remote goblet People say it's hard, but you'll get the hand of it soon, also you better be using hikari
You think i know what hikari is
๐คฆ
So far
MySQL looks like i'd mostly need to learn the key words such as select, from, delete, where, alter, update, ect
@violet creek Hey, I saw you were playing around with tab completion packets a couple years ago, did you ever figure that out properly or?
it's going well lmaooo
uSe HiKaRi
smd
You'll thank me later, just do it
Jumbo Hey, I saw you were playing around with tab completion packets a couple years ago, did you ever figure that out properly or?
@hot hull "a couple years ago" I bet you don't remember what you have done yesterday lmao xd
I actually do! I can't remember for the day before that tho
xd
Ah yes I love it when IJ defaults to desktop as default directory -.-
@hot hull yeah I did. You can just use protocollib for that, and use their premade wrapper for the packet.
Then you can remove and add keywords from the tabcompletion.
1.2.5
Cause I see that for 1.13 there's a new event, so just testing out what exactly the event does rn
Hibernate
Niall, do you know if it would be complicated to make a similar system to paypals messaging system? That might be really complicated lol
Basically its a live chat, but its not always live, like it can just be messaging
still gotta fix my registration/login tho :p
Hm well it wouldn't be too hard
I would use websockets to be honest.. not that I know how to (with spring)
I've only ever done websockets with Netty and JavaWebsockets
Netty is a little bit of a pain
hm alright, i gotta fix my login/registration first lol, if the email is the same the page just refreshes
kekW
oof
@heady birch any clue why the page is just refreshing lol?
And then it appears blank
when the email matches
Cuz you did something wrong :p
yw
Why didnt i think of that
Would it be like a problem with the controller?
@PostMapping("/user/registration")
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid UserDto userDto, HttpServletRequest request, Errors errors, ModelAndView mav){
try{
User register = userService.registerNewUserAccount(userDto);
} catch (UserAlreadyExistsException e) {
new ModelAndView("registration", "message", "An account with this email already exists");
}
return new ModelAndView("successRegister", "user", userDto);
}```
Whats a ModelAndView? And what would making a new one do?
hol up
maybe im just being stupid
Not sure if thats the problem it could well be
now the page just refreshes, like it doesnt give any feedback that the email has an account
Do you have your ${message} in tyhymeleaf?
Yes but add a th:if="${message != null}" to that h1 as well
ah
when i try to go to /user/login i get like a type=notFound error
i dont think i finished setting it up from the other day
ye
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/user/registration").permitAll()
.antMatchers("/user/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/user/login")
.passwordParameter("password")
.usernameParameter("username")
.loginProcessingUrl("/user/login")
.failureUrl("/login?error=true");
}```
Do you have controller mapping?
@GetMapping("/user/login)
public String loginPage() {
return "your login template";
}
Just add a get mapping
Yeah
But the post mapping would handle it
But we dont need one because spring handles it
ah
Unlike the registration form which does have a post mapping
I did the form and the page refreshsed, idk if it worked or not lol
Did it add ?error=true at the url?
Change the processing URL to /user/login/p
And make the form th:action="@{/user/login/p}" see if that helps
nope
Page could be cached?
Make sure you dont resubmit the form
But refresh the form page then re enter details
yea, i cleared my caches and then refreshed and re entered
wait im getting an erropr
If the email doesnt exist I get an NPE
and if it does exist even if the passwords right
I get a
InternalAuthenticationServiceException: failed to lazily initialize a collection of role: com.aj.website.User.roles, could not initialize proxy - no Session**
Hm
Is your RoleRepository marked with @Repository
Or if you dont have one make sure you have a RoleRepository
oh, its it integer roke? My user one is User Long
It don't really matter
I mean you wont have trillions of roles
Int will easily handle it
alrgiht, whys that?
I used GenerationType.IDENTITY to work with my old database
Building from scratch you can use GenerationType.AUTO and hibernate handles it
ah
on enable I get
Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource ...
yea
Somewhere within the stacktrace
Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.facto
Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Integer
Is it meant to be Role Integer
Not Integer role
same thing
like from earlier not the startup error
InternalAuthenticationServiceException: failed to lazily initialize a collection of role: com.aj.website.User.roles, could not initialize proxy - no Session**
@ManyToMany(fetch = FetchType.EAGER)
where?
ah
if the email exists
Encoded password does not look like BCrypt
IF the username doesnt exist i get an NPE
Oh yeah
Delete your account in the database
In your UserService account creation code ensure the password is actually encoded
user.setPassword(passwordEncoder.encode(password));
passwordEncoder can be autowired
Still just nothing happens when i type in the right password or the wrong one
NPE if i type in the username or wrong email
Probably because there is no success url
Lets sort out the npe first
What is the NPE?
its at this line
return new org.springframework.security.core.userdetails.User(user.getEmail(),user.getPassword().toLowerCase(), true,true,true,true, getAuthorities(user.getRoles()));
Add this above that
throw new UsernameNotFoundException("Invalid username");
}```
That exception is built in to spring
ah ok
I want users to be able to login via username as well, not just email
That also means ill need a check if the username is already taken
You can probably adapt it
In your user repository add a method like this
findByUsernameEqualsOrEmailEquals(String username, String email);
alright
Then use that instead of what your using to get the User
does that replace getUserByEmail?
Yeah
alright
Now its telling me i need to implement loadUserByUsername do i just do the same process as email for htat?
actually nvm
?
yea so its telling me my old method doesnt override anymore, and it made me implement a new one, and that new one doesnt take in an email
in UserService this is
Keep that method how it is
Its telling me it doesnt override anymroe
God fucking damnit I broke crafting
I have absolutely no fucking clue how I managed to do that
Think I explained badly
We dont change parameters in loadByUsername
Can you send the UserService source?
Please use a paste service to share configs, errors, code and long logs.
โข HelpChat Paste
We still accept the "username" but use the username to lookup as an email or username
User user = userRepository.findUserByUsernameEqualsOrEmailEquals(email, email);
Yikes long methodnames
why do we use email twice?
Because that method accept email and username
The email we provide could be either
Whatever is in the username or email box
@Repository
UserRepository {
User findUserByUsernameEqualsOrEmailEquals(String username, String email);
}```
ah
Just a pseudocode
ye
Add that method to your user repository interface
A spring is clever and automatically implements it
You logged in successfully I expect
the page just refreshe, no error, its as if nothings happend
In your loginForm() section is security config
.defaultSuccessUrl("/", true)
Put where you want it to redirect you when logged in
is ?error=true in the url bar
no
Because any way we need to show the error message to the user
<div class="alert alert-danger" th:if="${param.error}"
th:with="errorMsg=${session['SPRING_SECURITY_LAST_EXCEPTION'].message}">
<span th:text="${errorMsg}">Error</span>
</div>
I use this but this also uses bootstrap so just remove the class= part
alright
But im not too sure about that otherwise
lol still nothing
Lets see controller code
=paste
Please use a paste service to share configs, errors, code and long logs.
โข HelpChat Paste
https://paste.helpch.at/aneripopow.java idk if i was meant to use the same class for registration and login lol
https://i.imgur.com/TvtL3v1.png lol nice
Yeah fine, what about login.html
Did you delete your user like I said earlier (when we did password encryption)
Can you send security config?
Maybe chuck on .permitAll() on the end of failureURL
alright
See what happens
.failureUrl("/user/login?error=true");
So the reason it kept refreshing because we didnt have permission to process the login for some reason, so it redirects us to a the login
ah
If we access any page without permission spring redirects us to the login
ah thats good
now it just tells me ive got bad credentials evertime
imma delete myself from the db and re register just to make sure my credentials are actually bad lol
yeas it just says bad credentials everyime
Spring will always say "bad credentials" and wont say wether its username password, e.g I looked into saying what it specifically is.. But it's actually more secure to just say that general message
Hm
I dont think you should convert your password to lower case in UserService
No
eyyyyy
now like
eill pages be only accesible if you logged in, unless i permit all?
yeah
ah
nice
this is kinda random, but in theory could I integrate JDA into a website?
like in the same code
no clue what that is lol
like networking library
ah
now imma do some frontend stuff so this looks presentable
What do I do if i want like either LOGIN or THEIRUSERNAME in like the top left corner
like on the main page
In the controller I usually add the current user as a atttribute to the model
then check if it's null
where do i get the user from?
@GetMapping
public String homepage(Model model, @AuthenticationPrincipal User user) {`
if (user != null) {
model.addAttribute("user", userRepository.findUserByUsername(username));
}
return "homepage";
}
Now before this works
In your UserService where we create the spring UserDetails
So does getmapping just get it for everything unless its already assigned something else?
like by itself with no params
No
GetMapping just handles an HTTP get
It can still handle ?= in the url
But not form submissions
to handle everything use @RequestMapping
huh
basically just use a GetMapping
alright
ah
So that would handle http://localhost:8080/
Ignore that
We created UserDetails with user.getEmail() which is fine
So we need to make sure we get the User by email in the controller
model.addAttribute("user", userRepository.findUserByUsernameEqualsOrEmailEquals(user.getEmail(),user.getEmail()));?
then in my html file i just add like something like th:idk="${user} or something along those lines?
userRepository.findUserByEmail(user.getUsername())
then in my html file i just add like something like
th:idk="${user}or something along those lines?
@obtuse gale Yeah
userRepository.findUserByEmail(user.getUsername())
@heady birch You need to use to get the User
well my userrepo only has
userRepository.findUserByUsernameEqualsOrEmailEquals(user.getEmail(),user.getEmail())
Oh just create User findUserByEmail(String email); in their
In this case @AuthenticaionPrinciple User user is the Spring UserDetails class
ah
@GetMapping
public String index(Model model, @AuthenticationPrincipal UserDetails user) {
if (user != null) {
model.addAttribute("user", userRepository.findUserByEmail(user.getUsername()));
}
return "index";
}```
Im refering to old code I think this can be done better with a controller advice
huh?
@ControllerAdvice(annotations = Controller.class)
public class UserControllerAdvice {
@Autowired
UserRepository userRepository;
@ModelAttribute("user")
public User getUser() {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (userDetails == null) {
return null;
}
return userService.findUserByEmail(userDetails.getUsername());
}```
Make this a class
which user to i use
Import your User class
@GetMapping
public String index() {
return "index";
}```
Then I think you can just do this in your main controller
alrihgt
java.lang.String cannot be cast to class org.springframework.security.core.userdetails.UserDetails
@ControllerAdvice(annotations = Controller.class)
public class UserControllerAdvice {
@Autowired
UserRepository userRepository;
@ModelAttribute("user")
public User getUser() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth == null) {
return null;
}
return userService.findUserByEmail(auth.getName());
}
}```
Maybe try this
Oh yeha
userRepository
Have a good night
Revisiting spring has made me realise I can improve my code ๐
yea, just for tomomrow what do i use for the html? Its like th:something="${user}" rihgt?
Yep
To get username you would do
<span th:text="${user.username}">
<span th:text="${user.email}">
e.g
Can put that in other things besides a <span>
and you can access anything in your User object
๐
Damn a maxrankup command is fucking easy
Time to get to work on my next client's plugin
What do yall do? Test while developing like every day or finish the plugin and then test?
I personally test while developing, cos i fk stuff up alot lol
I usually don't
More specifically, I do one feature of the plugin, test
ah
I just test at the end
Expect to have to fix 10 bugs before being able to start the plugin
Then another 15 upon joining the server
Then another 10-15
Then I'm done
I do something, test, do more, test, and repeat until it works
I only do that for plugin updates
LOL
ight so i'm trying to compile PlotSquared and it can't seem to find the .git file, any ideas?
Is there a legit way to unregister a command from the server
Tab completion and all
@chilly jungle I did a few tests and well.. kinda?
For some reason it still shows on the tab complete
You have to remove it from knownCommands
intellij
I did it yeah Glare still shows somehow
I could find a way around it though, like saving the removed command name to a list and canceling it from the tab complete
I guess that's a way. Just annoying.
I could play with the command map tomorrow to see if i can completely remove it
Do I actually need to do this?
FileConfiguration config;
File cfile;
config = getConfig();
config.options().copyDefaults(true);
saveConfig();
cfile = new File(getDataFolder(), "config.yml");
Since I can have the default one
@ocean quartz thats as far as I have gotten
Yeah, tomorrow I'll try removing the tab complete as well and will let you know
I am wondering what's behind the scene of Barry's random xp generator wheel
a lot of images
I mean, idk which spin type it is
=xp spin
what's the command
Lol
=xp wheel
=wheel
yeah it's just a whole lotta images & gifs
Is it actually ๐ค
pretty sure
It is
No way i am gonna add 100+ imgs on different angle
Cube showed all the images for it once
Idfk that was months ago
Like 50 pastes daily are mine lmao
Btw reason i asked it was I would like to add the spin-to-win wheel on image map
But seeing that behind the scene for it with barry... no way
Just make a gif which does like 6 rotations, then just play the gif at a specific timepoint, and put an ending image when it finishes
Find Slovenia on there piggy
I am wondering if they are all exact timed on gif
slovenia: n/a
๐
I mean it makes sense, but still
vietnam 228
Sure ๐
apparently brazil tries to attack the site a lot
343 threats from brazil in the last 24 hours
I thought it's ddos protected ?
yeah, that's blocked attacks
not necessarily ddos attacks
just some sort of attack
Also, about the wheel, are the gif having exact time length or what, because there is no way i will make it in obvious way
idk how it works behind the scenes
Or are all the spinning speed gif are the same
Cube knows ๐
I am actually gonna use the old school wheel on the map then, by creating a flash on the selected choice (16 imgs, 8 choices)
Its pretty easy
You can makes gifs not loop
So there are 8 gifs
all ending on a different slot
once the gif finishes barry edits the message to swap out the gif with a still image of the last frame
With the wheel that falls into different angle of the selection pointed, how would you do it
Is the last frame gotten by manual programming?
it never falls on a different angle
it always finishes perfectly in the middle of a section
How hard would it be with spring to make it so its like a messaging system with spring, that can only be seen by staff
So its like a private ticket with staff
Live chat or Like a github issue/ticket system
Are you familiar with paypals live chat system?
Its like a live chat, but its not always live, like if someones not available the message just stays there until someone is, and can reply
No
hard?
Don't really know
@pallid gale it's different on the Barry's ban wheel i think
Sometimes i see the pointer not actually point to the center
No idea why I can't download this image but...
Idk it's mistake from aligning or is that how it's supposed to be different lol
Should I use Kotlin for a library? Only downside is my library will include the kotlin stdlib
And this stupid generation.
@topaz bay
"People that had one job and failed"
Cj
I can see why you are an eclipser
fools
Respect(: