/**
 * Created by jaskokoyn on 2/17/2015.
 */
owlChatApp.controller( "registerController", ["$scope", "$http", function($scope, $http){
    $scope.regUser              =   {
        username:                   null,
        email:                      null,
        pass1:                      null,
        pass2:                      null
    };

    $scope.register             =   function(){
        $("#registerForm").slideUp('fast', function(){
            $("#registerStatus").html(
                '<div class="alert alert-info"><strong>Please wait!</strong> We are now creating your account.</div>'
            ).hide().slideDown('fast');

            $http({
                method: 'POST',
                url: 'actions/users/register.php',
                data: $scope.regUser
            }).success(function(data,status,headers,config){
                if(data.status == 2){
                    $("#registerStatus").html(
                        '<div class="alert alert-success"><strong>Success!</strong> Your account has been created.</div>'
                    );
                    location.reload();
                }else{
                    $("#registerStatus").html(
                        '<div class="alert alert-warning"><strong>Warning!</strong> ' + data.message + '</div>'
                    );
                    $("#registerForm").slideDown('fast');
                }
            });
        });
    };
}]);