Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Form */
- <form ng-submit="submit(user)" class="uk-form uk-form-horizontal ng-pristine ng-valid"
- id="login" name="login">
- <div id="messages" class="uk-alert uk-alert-danger uk-animation-slide-top" data-ng-show="messages" data-ng-bind="messages"></div>
- <div class="uk-form-row">
- <label for="email" class="uk-form-label">Email</label>
- <div class="uk-form-controls">
- <input placeholder="email/username" name="email" type="email" id="email" ng-model="user.email">
- </div>
- </div>
- <div class="uk-form-row">
- <label for="password" class="uk-form-label">Password</label>
- <div class="uk-form-controls">
- <input placeholder="password" name="password" type="password" value="" id="password" ng-model="user.password">
- </div>
- </div>
- <div class="uk-form-row">
- <div class="uk-form-controls">
- <input class="uk-button-primary" type="submit" value="Login">
- <a href="#">Forgot password?</a>
- </div>
- </div>
- </form>
- /* LoginController.js */
- define(['app/app'], function (app) {
- 'use strict';
- app.register.controller('LoginController', ['$scope', '$location', '$filter','$http',
- function ($scope, $location, $filter,$http) {
- $scope.$on('$routeChangeSuccess', function () {
- require([
- 'jquery',
- 'uikit',
- 'jquery.validate'
- ], function ($) {
- function errorPlacement(error, element) {
- element.after(error);
- error.addClass('uk-alert uk-alert-danger uk-animation-slide-top');
- }
- $("#login").validate({
- errorPlacement: errorPlacement,
- errorElement: "div",
- rules: {
- email: {
- required: true
- },
- password: {
- required: true
- }
- }
- });
- });
- });
- $scope.submit = function (user) {
- if ($("#login").valid()) {
- $http.post(
- '/login',
- {
- 'email': user.email,
- 'password': user.password
- }
- ).success(function (data) {
- if (data.status == true) {
- $location.path("/dashboard");
- } else {
- $scope.messages = data.msg;
- }
- });
- }
- };
- }]);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement