Skip to content

Commit

Permalink
feat(server): show notice in admin login to reset password when regis…
Browse files Browse the repository at this point in the history
…tered via Google (#530)
  • Loading branch information
fushar authored Oct 16, 2023
1 parent bcd9711 commit dbca4d0
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ public void run(JudgelsServerApplicationConfiguration config, Environment env) t

private void runMichael(JudgelsServerApplicationConfiguration config, Environment env) {
JudgelsServerConfiguration judgelsConfig = config.getJudgelsConfig();
JophielConfiguration jophielConfig = config.getJophielConfig();
SandalphonConfiguration sandalphonConfig = config.getSandalphonConfig();

MichaelComponent component = DaggerMichaelComponent.builder()
.judgelsServerModule(new JudgelsServerModule(judgelsConfig))
.judgelsSchedulerModule(new JudgelsSchedulerModule(env))
.judgelsHibernateModule(new JudgelsHibernateModule(hibernateBundle))
.authModule(new AuthModule(jophielConfig.getAuthConfig()))
.rabbitMQModule(new RabbitMQModule(judgelsConfig.getRabbitMQConfig()))
.gabrielClientModule(new GabrielClientModule(sandalphonConfig.getGabrielConfig()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dagger.Component;
import javax.inject.Singleton;
import judgels.JudgelsServerModule;
import judgels.jophiel.auth.AuthModule;
import judgels.jophiel.hibernate.JophielHibernateDaoModule;
import judgels.messaging.rabbitmq.RabbitMQModule;
import judgels.michael.account.role.RoleResource;
Expand Down Expand Up @@ -48,6 +49,7 @@
SandalphonHibernateDaoModule.class,

// 3rd parties
AuthModule.class,
RabbitMQModule.class,
GabrielClientModule.class,
SandalphonClientModule.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.ws.rs.core.UriInfo;
import judgels.jophiel.api.session.Session;
import judgels.jophiel.api.user.User;
import judgels.jophiel.auth.google.GoogleAuth;
import judgels.jophiel.session.SessionStore;
import judgels.jophiel.session.SessionTokenGenerator;
import judgels.jophiel.user.UserStore;
Expand All @@ -32,6 +33,7 @@
public class IndexResource extends BaseResource {
private static final String POST_LOGIN_URL = "/problems";

@Inject protected Optional<GoogleAuth> googleAuth;
@Inject protected SessionStore sessionStore;
@Inject protected UserStore userStore;
@Inject protected UserRegistrationEmailStore userRegistrationEmailStore;
Expand All @@ -57,8 +59,9 @@ public Response login(@CookieParam("JUDGELS_TOKEN") String token) {

private View renderLogin(LoginForm form) {
HtmlTemplate template = newTemplate();
template.setContentLayoutClassName("login-layout");
template.setTitle("Log in");
return new LoginView(template, form);
return new LoginView(template, form, googleAuth.isPresent());
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
import judgels.michael.template.TemplateView;

public class LoginView extends TemplateView {
public LoginView(HtmlTemplate template, LoginForm form) {
private boolean hasGoogleAuth;

public LoginView(HtmlTemplate template, LoginForm form, boolean hasGoogleAuth) {
super("loginView.ftl", template, form);
this.hasGoogleAuth = hasGoogleAuth;
}

public boolean getHasGoogleAuth() {
return hasGoogleAuth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class HtmlTemplate {
private final String name;

private String contentLayoutClassName = "";
private String title = "";
private String username = "";
private String avatarUrl = "";
Expand All @@ -29,6 +30,14 @@ public String getName() {
return name;
}

public String getContentLayoutClassName() {
return contentLayoutClassName;
}

public void setContentLayoutClassName(String contentLayoutClassName) {
this.contentLayoutClassName = contentLayoutClassName;
}

public String getTitle() {
return title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ input[type="text"], input[type="password"], textarea {
border: 1px solid var(--accent-color);
}

.login-layout {
min-height: unset;
}

.title-inline {
margin-bottom: 10px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
<@forms.password name="password" label="Password" required=true/>
<@forms.submit>Log in</@forms.submit>
</@forms.form>

<#if hasGoogleAuth>
<br>
<br>
<p><small>Registered via Google? Go to <strong>My account</strong> &rarr; <strong>Reset password</strong> to set your password.</small></p>
</#if>
</@template.layout>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#macro layout>
<div class="content">
<div class="content ${vars.contentLayoutClassName}">
<#nested>
</div>
</#macro>

0 comments on commit dbca4d0

Please sign in to comment.