#!/bin/sh

dia=/usr/bin/dialog
admin_file=/mnt/file/admin.dat
kefu_file=/mnt/file/Student.dat
chuna_file=/mnt/file/chuna.dat
msg(){
    $dia --title "T&I" --msgbox "$1" 15 30
}
login(){
    $dia --menu "请选择登录用户类型" 10 30 3 1 "系统管理员" 2 "客服" 3 "出纳" 2>/mnt/file/1.txt
    select=$(cat /mnt/file/1.txt)
#    rm -fr /mnt/file/2.txt
    case $select in
    1)
      $dia --title "请输入用户信息 " --inputbox "管理员账号:" 15 20 2>/mnt/file/1.txt
         admin_name=$(cat /mnt/file/1.txt)
         export n=$(cat $admin_file | awk -F ',' '{print $1}' )
            if [ $n = $admin_name ]
            then
                 msg "用户名验证通过"
            else
                 msg "用户名验证失败"
               return
            fi
            continue
      $dia --title "请输入管理员密码" --insecure --passwordbox "密   码:" 15 20 2>/mnt/file/1password.txt
          admin_password=$(cat /mnt/file/1password.txt)
            export n=$(cat $admin_file | awk -F ',' '{print $2}' )
            if [ $n = $admin_password ]
         then
                msg "您输入的管理员密码正确 !"
            else
                 msg "用户名验证失败"
               return
            fi
            continue
      ;;
    2)
       $dia --title "请输入用户信息 " --inputbox "客服账号:"  15 20 2>/mnt/file/kefu.txt
            kefu_name=$(cat /mnt/file/kefu.txt)
            export n=$(cat $kefu_file | awk -F ',' '{print $1}' )
            if [ $n =  $kefu_name ]
            then
                msg "用户名验证通过 !"
             else
                 msg "用户名验证失败"
               return
            fi
            continue
 
       $dia --title "请输入用户密码" --insecure --passwordbox "密   码:" 15 20 2>/mnt/file/kefu_password.txt
          kefu_password=$(cat /mnt/file/kefu_password.txt)
            export n=$(cat $kefu_file | awk -F ',' '{print $2}' )
            if [ $n = $kefu_password ] ; then
                msg "您输入的用户密码正确 !"
           else
                 msg "用户名验证失败"
               return
            fi
            continue
           exit 1
      ;;
   3)
      $dia --title "请输入用户信息 " --inputbox "出纳账号:"  15 20 2>/mnt/file/chuna.txt
           chuna_name=$(cat /mnt/file/chuna.txt)
            export n=$(cat $chuna_file | awk -F ',' '{print $1}' )
            if [ $n = $chuna_name ]
            then
                msg "用户名验证通过 !"
            else
                 msg "用户名验证失败"
               return
            fi
            continue
 
       $dia --title "请输入用户密码" --insecure --passwordbox "密   码:" 15 20 2>/mnt/file/chuna_password.txt
          kefu_password=$(cat /mnt/file/kefu_password.txt)
            export n=$(cat $kefu_file | awk -F ',' '{print $2}' )
            if [ $n = $kefu_password ] ; then
                msg "您输入的用户密码正确 !"
           else
                 msg "用户名验证失败"
               return
            fi
            continue
           exit 1
      ;;
   3)
      $dia --title "请输入用户信息 " --inputbox "出纳账号:"  15 20 2>/mnt/file/chuna.txt
           chuna_name=$(cat /mnt/file/chuna.txt)
            export n=$(cat $chuna_file | awk -F ',' '{print $1}' )
            if [ $n = $chuna_name ]
            then
                msg "用户名验证通过 !"
            else
                 msg "用户名验证失败"
               return
            fi
            continue
 
       $dia --title "请输入用户密码" --insecure --passwordbox "密   码:" 15 20 2>/mnt/file/chuna_password.txt
             kefu_password=$(cat /mnt/file/kefu_password.txt)
            export n=$(cat $kefu_file | awk -F ',' '{print $2}' )
            if [ $n = $kefu_password ] ; then
                msg "您输入的用户密码正确 !"
           else
                 msg "用户名验证失败"
               return
            fi
            continue
           exit 1
      ;;
   3)
      $dia --title "请输入用户信息 " --inputbox "出纳账号:"  15 20 2>/mnt/file/chuna.txt
           chuna_name=$(cat /mnt/file/chuna.txt)
            export n=$(cat $chuna_file | awk -F ',' '{print $1}' )
            if [ $n = $chuna_name ]
            then
                msg "用户名验证通过 !"
            else
                 msg "用户名验证失败"
               return
            fi
            continue
 
       $dia --title "请输入用户密码" --insecure --passwordbox "密   码:" 15 20 2>/mnt/file/chuna_password.txt
  chuna_password=$(cat /mnt/file/chuna_password.txt)
  export n=$(cat $chuna_file | awk -F ',' '{print $2}' )
            if [ $n = $chuna_password ]
            then
                msg "您输入的用户密码正确 !"
            else
                 msg "用户名验证失败"
               return
            fi
            continue
 
      esac
}
login