github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-master/asset_client/src/views/login_form.js (about)

     1  /**
     2   * Copyright 2017 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   * ----------------------------------------------------------------------------
    16   */
    17  'use strict'
    18  
    19  const m = require('mithril')
    20  
    21  const api = require('../services/api')
    22  const transactions = require('../services/transactions')
    23  const forms = require('../components/forms')
    24  
    25  /**
    26   * The Form for authorizing an existing user.
    27   */
    28  const LoginForm = {
    29    view (vnode) {
    30      const setter = forms.stateSetter(vnode.state)
    31  
    32      return m('.login-form', [
    33        m('form', {
    34          onsubmit: (e) => {
    35            e.preventDefault()
    36            const credentials = {
    37              username: vnode.state.username,
    38              password: api.hashPassword(vnode.state.password)
    39            }
    40            api.post('authorization', credentials)
    41              .then(res => {
    42                api.setAuth(res.authorization)
    43                transactions.setPrivateKey(vnode.state.password,
    44                                           res.encryptedKey)
    45                m.route.set('/')
    46              })
    47          }
    48        },
    49        m('legend', 'Login Agent'),
    50        forms.textInput(setter('username'), 'Username'),
    51        forms.passwordInput(setter('password'), 'Password'),
    52        m('.container.text-center',
    53          'Or you can ',
    54          m('a[href="/signup"]',
    55            { oncreate: m.route.link },
    56            'create a new Agent')),
    57        m('.form-group',
    58          m('.row.justify-content-end.align-items-end',
    59            m('col-2',
    60              m('button.btn.btn-primary',
    61                {'data-toggle': 'modal', 'data-target': '#modal'},
    62                'Login')))))
    63      ])
    64    }
    65  }
    66  
    67  module.exports = LoginForm