WMS系统后端开发-用户权限

Account API

using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Web.Http;
using WMS_WebAPI.Models;
using WMS_WebAPI.Models.Context;

namespace WMS_WebAPI.Controllers
{
    [Authorize]
    public class AccountController : ApiController
    {
        WMS_Entities _context;
        AccountController()
        {
            _context= new WMS_Entities();
        }

        /// <summary>
        ///  user name  and password  filed  data  required
        /// </summary>
        /// <param name="user">Username,Password required</param>
        /// <returns></returns>
       
        [HttpPost]
        [Route("api/Login")]
        [AllowAnonymous]
        public IHttpActionResult Login([FromBody] LoginModel user)
            {
            if (!ModelState.IsValid)
            {
                return NotFound();
            }
                
                var model = _context.Accountuser_Login(user.Username, user.Password).ToList();
                //FirstOrDefault();
                if (model != null)
                {
                    
                    if (model[0].UserID > 0)
                    {
                        string token = createToken(user.Username);
                        ApplicationUser appuser = new ApplicationUser();
                        appuser.UserID = Convert.ToInt32(model[0].UserID);
                        appuser.CompanyID = Convert.ToInt32(model[0].CompanyID);
                        appuser.Token = token;
                        //appuser.sploginlist = model;
                        var users = _context.Users.FirstOrDefault(s => s.UserID == appuser.UserID);
                        appuser.RoleID = users.RoleID;
                        var yearList = _context.Finacialyear_Select().ToList();
                        var currentUser = new { user = appuser, warehouseList = model,finantialYears= yearList };

                        return Ok(currentUser);
                    }
                    
                    return Ok(false);
                    
                }
                else
                {
                    return NotFound();
                }
           
        }

        /// <summary>
        /// Get GetfinantialYears Info
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("api/finantialYears")]
        public IHttpActionResult GetfinantialYears()
        {
            var data = _context.Finacialyear_Select().ToList();
            if (data == null)
            {
                return NotFound();
            }

            return Ok(data);
        }

        private string createToken(string username)
        {     
            //Set issued at date
            DateTime issuedAt = DateTime.UtcNow;
            //set the time when it expires
            DateTime expires = DateTime.UtcNow.AddDays(7);


            var tokenHandler = new JwtSecurityTokenHandler();

            //create a identity and add claims to the user which we want to log in
            System.Security.Claims.ClaimsIdentity claimsIdentity = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.Name, username)
            });

            const string sec = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1";
            var now = DateTime.UtcNow;
            var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(System.Text.Encoding.Default.GetBytes(sec));
            var signingCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature);


            //create the jwt
            var token =
                (JwtSecurityToken)
                    tokenHandler.CreateJwtSecurityToken(issuer: "http://localhost:50191", audience: "http://localhost:50191",
                        subject: claimsIdentity, notBefore: issuedAt, expires: expires, signingCredentials: signingCredentials);
            var tokenString = tokenHandler.WriteToken(token);

            return tokenString;
        }

    }
}

 Users API

using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.Http;
using WMS_WebAPI.Models;
using WMS_WebAPI.Models.Context;

namespace WMS_WebAPI.Controllers
{
    public class UsersController : ApiController
    {
        WMS_Entities _context = new WMS_Entities();
        CommanListToDataTableConverter ConvertDataTable = new CommanListToDataTableConverter();
        string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
        [HttpGet]
        [Route("api/Users/Users_Select")]
        public IHttpActionResult Users_Select()
        {
            try
            {
                var data = _context.Users_Select().ToList();
                if (data == null)
                {
                    return NotFound();
                }
                return Ok(data);
            }
            catch (System.Exception)
            {

                return BadRequest();
            }

        }


        [HttpPost]
        [Route("api/Users/Users_Insert")]
        public IHttpActionResult Users_Insert(cls_Users obj)
        {

            DataTable dtLcls_TD_Users = new DataTable();
            dtLcls_TD_Users = ConvertDataTable.ConvertToDataTable(obj.Lcls_TD_Users);
           
            DataSet ds = new DataSet();
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionstring))
                {
                    using (SqlCommand command = new SqlCommand("Users_Insert", connection))
                    {

                        command.CommandType = System.Data.CommandType.StoredProcedure;
                        SqlParameter[] param = new SqlParameter[9];
                        param[0] = new SqlParameter("@UserID", Convert.ToInt32(obj.UserID));
                        param[1] = new SqlParameter("@UserName", Convert.ToString(obj.UserName));
                        param[2] = new SqlParameter("@UserDetail", Convert.ToString(obj.UserDetail));
                        param[3] = new SqlParameter("@Password", Convert.ToString(obj.Password));
                        param[4] = new SqlParameter("@RoleID", Convert.ToInt32(obj.RoleID));
                        param[5] = new SqlParameter("@UserTypeID", Convert.ToInt32(obj.UserTypeID));
                        param[6] = new SqlParameter("@CreatedBy", Convert.ToInt32(obj.CreatedBy));

                        param[7] = new SqlParameter("@CreatedBy", Convert.ToInt32(obj.CreatedBy));
                      
                        param[8] = new SqlParameter("@UserCompany", dtLcls_TD_Users);
                        param[8].SqlDbType = SqlDbType.Structured;
                      

                        command.Parameters.AddRange(param);
                        connection.Open();
                        using (SqlDataAdapter da = new SqlDataAdapter(command))
                        {
                            da.Fill(ds);
                        }
                        connection.Close();
                    }
                    return Ok(ds);
                }
            }
            catch (System.Exception ex)
            {
                return BadRequest(ex.Message);
            }

        }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
C#开发,可解析WMS服务,并进行浏览,功能强大,GIS开发人员可参考文件列表 Get Capabilities Example ........................\AssemblyInfo.cs ........................\Get Capabilities Example.csproj ........................\GetCapabilitiesExample.cs Get Map Asynch Example ......................\AssemblyInfo.cs ......................\Get Map Asynch Example.csproj ......................\GetMapAsynchExample.cs ......................\GetMapAsynchExample.resx Get Map Example ...............\AssemblyInfo.cs ...............\Get Map Example.csproj ...............\GetMapExample.cs GLOBECapabilities20040423.xml MapAnimation ............\AssemblyInfo.cs ............\Map Animation.csproj ............\MapAnimation.cs ............\MapAnimation.resx WMS Overview Article.html WMS Overview.sln Wms.Client ..........\AssemblyInfo.cs ..........\Capabilities.cs ..........\CLSDFOLD.BMP ..........\DefaultServerDescriptors.xml ..........\DownloadCache.cs ..........\ENTIRNET.BMP ..........\ENTIRNETX.bmp ..........\ENTIRNETX.ICO ..........\ExtensionMap.cs ..........\Layer.cs ..........\OPENFOLD.BMP ..........\PreviewDialog.cs ..........\PreviewDialog.resx ..........\RequestBuilder.cs ..........\Retriever.cs ..........\Server.cs ..........\ServerAddDialog.cs ..........\ServerAddDialog.resx ..........\ServerDescriptor.cs ..........\Wms.Client.csproj ..........\WmsDialog.cs ..........\WmsDialog.resx ..........\WmsException.cs ..........\WmsServerDescriptors.cs ..........\WmsServerDescriptors.xsd WMSBrowser ..........\AssemblyInfo.cs ..........\MapForm.cs ..........\MapForm.resx ..........\WMSBrowser.cs ..........\WMSBrowser.csproj ..........\WMSBrowser.resx
BS .net 4.0 C# Web SQL Server 2012-2017 Fastreport报表 介绍一套仓储管理系统源码,以下为作者留言 吉特仓储管系统基础版本 适合单仓库,基本的仓库入库管理,出库管理,盘点,报损,移库,库位等管理,有着可视化图表。 系统采用Bootstrap 开发,UI 相对比较简单,业务功能不复杂,适合一般的学习开发者。 软件声明 (1)软件允许各位开发者用于自己软件的项目开发,请保留软件标题信息,版权信息,在下不胜感激。 (2)坚决抵制某些企业拿了源程序,对外宣称是自己公司团队开发,如若发现必定网络舆论讨伐。 (3)由于之前开源的版本和一些企业闹出版权问题,吉特仓储管理系统均为自己开发,其他公开销售源码,软件的均为未经授权的盗版,为不法企业和个人。 (4)本人目前定制二次开发各种仓库系统,不单独销售成品软件,如有需求可以直接联系本人。 功能清单 主要包含功能如下: 系统管理 ----员工管理 ----角色管理 ----部门管理 ----菜单管理 ----权限分配 ----标识符管理 基本资料 ----供应商管理 ----库位管理 ----客户管理 ----计量单位 ----产品类别 ----产品管理 仓库管理 ----入库管理 ----出库管理 ----报损管理 ----移库管理 ----盘点管理 ----退货管理 报表管理 ----库存清单 ----货品统计 ----出入库报表 ----入库报表 ----出库报表 ----报损报表 ----退货报表 ----客户报表 ----供应商报表 ----台账记录 ----自定义报表 readme中有作者联系方式

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

!chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值