// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/ProfileConstants.java
// public class ProfileConstants {
// 
//     public static final String PARAM_AVATAR = "avatar";
//     public static final String PARAM_EMAIL = "email";
//     public static final String PARAM_FAMILY_NAME = "familyName";
//     public static final String PARAM_GIVEN_NAME = "givenName";
//     public static final String PARAM_PASSWORD = "password";
//     public static final String PARAM_USER_PROFILE_PATH = "profilePath";
// 
//     public static final String PROP_EMAIL = "email";
//     public static final String PROP_FAMILY_NAME = "familyName";
//     public static final String PROP_GIVEN_NAME = "givenName";
// }
// 
// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/services/AccountManager.java
// @Component
// @Service
// public interface AccountManager {
//     /**
//      * Creates a new user profile in the repository.
//      * @param userName user's login name
//      * @param password user's passward
//      * @param givenName user's first name
//      * @param lastName user's last name
//      * @param email user's email
//      * @param avatarParam user's avatar upload parameter. This parameter may be null.
//      * @return the newly created profile resource, null if failed to create one.
//      */
//     Resource createUser(String userName, String password, String givenName, String lastName, String email, RequestParameter avatarParam);
//     void changePassword(String newPassword, ResourceResolver resourceResolver);
// }
// 
// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/services/AvatarManager.java
// @Component
// @Service
// public interface AvatarManager {
// 
//     /**
//      * Updates an existing avatar or creates a new one.
//      * @param inputStream avatar's upload stream
//      * @param mimeType file mime type
//      * @param resourceResolver resource resolver created from the user's session
//      * @param userProfilePath path to the user's profile, <code>/home/user/bob@email.com</code> for example
//      */
//     void saveAvatar(final InputStream inputStream, final String mimeType,
//                     final ResourceResolver resourceResolver, final String userProfilePath);
// 
//     /**
//      * Creates the folder structure and stores avatar for a profile without a avatar.
//      * @param inputStream avatar's upload stream
//      * @param mimeType file mime type
//      * @param resourceResolver resource resolver created from the user's session
//      * @param userProfilePath path to the user's profile, <code>/home/user/bob@email.com</code> for example
//      */
//     void createAvatarWithDirectories(final InputStream inputStream, final String mimeType,
//                                      final ResourceResolver resourceResolver, final String userProfilePath);
// }


import com.adobe.ionicapp.profile.ProfileConstants;
import com.adobe.ionicapp.profile.services.AccountManager;
import com.adobe.ionicapp.profile.services.AvatarManager;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;
package com.adobe.ionicapp.profile.servlets;



@Component(immediate = true, metatype = true)
@Service(Servlet.class)
@Properties({
        @Property(name = "sling.servlet.resourceTypes", value = "sling/servlet/default"),
        @Property(name = "sling.servlet.methods", value = "POST"),
        @Property(name = "sling.servlet.selectors", value = "ionicapp.create"),
        @Property(name = "sling.servlet.extensions", value = "html")
})
public class CreateProfileServlet extends SlingAllMethodsServlet {

    private static final Logger LOG = LoggerFactory.getLogger(CreateProfileServlet.class);

    @Reference
    AccountManager accountManager;

    @Override
    public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/ProfileConstants.java
// public class ProfileConstants {
// 
//     public static final String PARAM_AVATAR = "avatar";
//     public static final String PARAM_EMAIL = "email";
//     public static final String PARAM_FAMILY_NAME = "familyName";
//     public static final String PARAM_GIVEN_NAME = "givenName";
//     public static final String PARAM_PASSWORD = "password";
//     public static final String PARAM_USER_PROFILE_PATH = "profilePath";
// 
//     public static final String PROP_EMAIL = "email";
//     public static final String PROP_FAMILY_NAME = "familyName";
//     public static final String PROP_GIVEN_NAME = "givenName";
// }
// 
// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/services/AccountManager.java
// @Component
// @Service
// public interface AccountManager {
//     /**
//      * Creates a new user profile in the repository.
//      * @param userName user's login name
//      * @param password user's passward
//      * @param givenName user's first name
//      * @param lastName user's last name
//      * @param email user's email
//      * @param avatarParam user's avatar upload parameter. This parameter may be null.
//      * @return the newly created profile resource, null if failed to create one.
//      */
//     Resource createUser(String userName, String password, String givenName, String lastName, String email, RequestParameter avatarParam);
//     void changePassword(String newPassword, ResourceResolver resourceResolver);
// }
// 
// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/services/AvatarManager.java
// @Component
// @Service
// public interface AvatarManager {
// 
//     /**
//      * Updates an existing avatar or creates a new one.
//      * @param inputStream avatar's upload stream
//      * @param mimeType file mime type
//      * @param resourceResolver resource resolver created from the user's session
//      * @param userProfilePath path to the user's profile, <code>/home/user/bob@email.com</code> for example
//      */
//     void saveAvatar(final InputStream inputStream, final String mimeType,
//                     final ResourceResolver resourceResolver, final String userProfilePath);
// 
//     /**
//      * Creates the folder structure and stores avatar for a profile without a avatar.
//      * @param inputStream avatar's upload stream
//      * @param mimeType file mime type
//      * @param resourceResolver resource resolver created from the user's session
//      * @param userProfilePath path to the user's profile, <code>/home/user/bob@email.com</code> for example
//      */
//     void createAvatarWithDirectories(final InputStream inputStream, final String mimeType,
//                                      final ResourceResolver resourceResolver, final String userProfilePath);
// }


// Path: aem-package/bundles/ionic-app-profile-manager/src/main/java/com/adobe/ionicapp/profile/servlets/CreateProfileServlet.java
import com.adobe.ionicapp.profile.ProfileConstants;
import com.adobe.ionicapp.profile.services.AccountManager;
import com.adobe.ionicapp.profile.services.AvatarManager;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;

package com.adobe.ionicapp.profile.servlets;



@Component(immediate = true, metatype = true)
@Service(Servlet.class)
@Properties({
        @Property(name = "sling.servlet.resourceTypes", value = "sling/servlet/default"),
        @Property(name = "sling.servlet.methods", value = "POST"),
        @Property(name = "sling.servlet.selectors", value = "ionicapp.create"),
        @Property(name = "sling.servlet.extensions", value = "html")
})
public class CreateProfileServlet extends SlingAllMethodsServlet {

    private static final Logger LOG = LoggerFactory.getLogger(CreateProfileServlet.class);

    @Reference
    AccountManager accountManager;

    @Override
    public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
        final String givenName = request.getParameter(ProfileConstants.PARAM_GIVEN_NAME);