<commit_before>/*
 * Databinder: a simple bridge from Wicket to Hibernate
 * Copyright (C) 2006  <NAME> <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package net.databinder.auth.components;

import net.databinder.auth.IAuthSession;
import net.databinder.auth.IAuthSettings;
import net.databinder.auth.data.IUser;
import net.databinder.components.DataStyleLink;
import net.databinder.components.SourceList;
import net.databinder.models.HibernateObjectModel;

import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.IClusterable;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;

/**
 * Serves as both a sign in and simple registration page. 
 */
public class DataSignInPage extends WebPage {
	private SourceList sourceList;
	
	private Component profileSocket, signinSocket;
	
	private SourceList.SourceLink profileLink, signinLink;
	
	public interface ReturnPage extends IClusterable {
		Page get();
	}
	private ReturnPage returnPage;

	/**
	 * Displays sign in page.
	 */
	public DataSignInPage(PageParameters params) {
		String username = params.getString("username");
		String token = params.getString("token");
		// e-mail auth, for example
		if (username != null && token != null) {
			IAuthSettings settings = ((IAuthSettings)Application.get());
			HibernateObjectModel userModel = new HibernateObjectModel(settings.getUserClass(),
					settings.getUserCriteriaBuilder(username));  
			IUser.CookieAuth user = (IUser.CookieAuth) userModel.getObject();
			if (user != null && user.getToken().equals(token))
				getAuthSession().signIn(user, true);
			setResponsePage(((Application)settings).getHomePage());
			setRedirect(true);
			return;
		}
		init();
	}
	public DataSignInPage(ReturnPage returnPage) {
		this.returnPage = returnPage;
		init();
	}
	protected void init() {
		add(new DataStyleLink("dataStylesheet"));
		
		sourceList = new SourceList();
		
		add(profileSocket = profileSocket("profileSocket", returnPage));
		add(new WebMarkupContainer("profileLinkWrapper") {
			public boolean isVisible() {
				return profileLink.isEnabled();
			}
		}.add(profileLink = sourceList.new SourceLink("profileLink", profileSocket)));
		
		add(signinSocket = signinSocket("signinSocket", returnPage));
		add(new WebMarkupContainer("signinLinkWrapper") {
			@Override<commit_msg>single contsructor with all funct.<commit_after>/*
 * Databinder: a simple bridge from Wicket to Hibernate
 * Copyright (C) 2006  <NAME> <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package net.databinder.auth.components;

import net.databinder.auth.IAuthSession;
import net.databinder.auth.IAuthSettings;
import net.databinder.auth.data.IUser;
import net.databinder.components.DataStyleLink;
import net.databinder.components.SourceList;
import net.databinder.models.HibernateObjectModel;

import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.IClusterable;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;

/**
 * Serves as both a sign in and simple registration page. 
 */
public class DataSignInPage extends WebPage {
	private SourceList sourceList;
	
	private Component profileSocket, signinSocket;
	
	private SourceList.SourceLink profileLink, signinLink;
	
	public interface ReturnPage extends IClusterable {
		Page get();
	}
	/**
	 * Displays sign in page.
	 */
	public DataSignInPage(PageParameters params) {
		this(params, null);
	}
	
	public DataSignInPage(ReturnPage returnPage) {
		this(null, returnPage);
	}
	
	public DataSignInPage(PageParameters params, ReturnPage returnPage) {
		if (params != null) {
			String username = params.getString("username");
			String token = params.getString("token");
			// e-mail auth, for example
			if (username != null && token != null) {
				IAuthSettings settings = ((IAuthSettings)Application.get());
				HibernateObjectModel userModel = new HibernateObjectModel(settings.getUserClass(),
						settings.getUserCriteriaBuilder(username));  
				IUser.CookieAuth user = (IUser.CookieAuth) userModel.getObject();
				if (user != null && user.getToken().equals(token))
					getAuthSession().signIn(user, true);
				setResponsePage(((Application)settings).getHomePage());
				setRedirect(true);
				return;
			}
		}

		add(new DataStyleLink("dataStylesheet"));
		
		sourceList = new SourceList();
		
		add(profileSocket = profileSocket("profileSocket", returnPage));
		add(new WebMarkupContainer("profileLinkWrapper") {
			public boolean isVisible() {
				return profileLink.isEnabled();
			}
		}.add(profileLink = sourceList.new SourceLink("profileLink", profileSocket)));
		
		add(signinSocket = signinSocket("signinSocket", returnPage));
		add(new WebMarkupContainer("signinLinkWrapper") {
			@Override
{'fraction_non_alphanumeric': 0.09880749574105621, 'fraction_numerical': 0.005265603221310206, 'mean_word_length': 4.735346358792185, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3233280', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1782, 'n_words': 553}