234 lines
11 KiB
C#
234 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
using NP.Model;
|
|
using System.Collections;
|
|
using NP.Base.Auth;
|
|
using NP.Base.ENUM;
|
|
using QRCoder;
|
|
namespace NP.Base.Controllers
|
|
{
|
|
public partial class FCommonController : NP.Base.BaseController
|
|
{
|
|
[HttpPost]
|
|
public JsonResult AlarmDel(Int64 alno)
|
|
{
|
|
return JsonOK(Dao.Save("lect.alarm.del", new Hashtable() { { "alno", alno }, { "userno", SUserInfo.UserNo } }));
|
|
}
|
|
[HttpPost]
|
|
public JsonResult QRCode()
|
|
{
|
|
var u = Dao.Get<Users>("users.users", new Hashtable() { { "userno", SUserInfo.UserNo } }).First();
|
|
string code = u.userid;
|
|
QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
|
QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
|
|
QRCode qrCode = new QRCode(qrCodeData);
|
|
//QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
|
|
//System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
|
|
//imgBarCode.4
|
|
//imgBarCode.Height = 150;
|
|
//imgBarCode.Width = 150;
|
|
var imgdata = "";
|
|
using (System.Drawing.Bitmap bitMap = qrCode.GetGraphic(20))
|
|
{
|
|
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
|
{
|
|
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
byte[] byteImage = ms.ToArray();
|
|
//imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
|
|
imgdata = "data:image/png;base64," + Convert.ToBase64String(byteImage);
|
|
}
|
|
//PlaceHolder1.Controls.Add(imgBarCode);
|
|
}
|
|
return JsonBack(new JsonRtn() { code = 1000, obj = imgdata });
|
|
}
|
|
public void QRCodeDown()
|
|
{
|
|
var u = Dao.Get<Users>("users.users", new Hashtable() { { "userno", SUserInfo.UserNo } }).First();
|
|
string code = u.userid;
|
|
QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
|
//QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
|
|
QRCodeData qrCodeData = qrGenerator.CreateQrCode(EncString(code), QRCodeGenerator.ECCLevel.Q);
|
|
QRCode qrCode = new QRCode(qrCodeData);
|
|
|
|
byte[] byteImage;
|
|
using (System.Drawing.Bitmap bitMap = qrCode.GetGraphic(20))
|
|
{
|
|
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
|
{
|
|
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
byteImage = ms.ToArray();
|
|
}
|
|
}
|
|
Response.Clear();
|
|
Response.ContentType = "application/force-download";
|
|
Response.AddHeader("content-disposition", "attachment; filename=kfcfqrcode.png");
|
|
Response.BinaryWrite(byteImage);
|
|
Response.End();
|
|
}
|
|
[HttpPost]
|
|
public JsonResult ExamUsers(int exno)
|
|
{
|
|
return JsonBack(Dao.Get<ExamUserRenew>("lect.myexamrenews", new System.Collections.Hashtable() { { "exno", exno }, { "userno", SUserInfo.UserNo } }));
|
|
}
|
|
[HttpPost]
|
|
public JsonResult ExamUserResult(int exno)
|
|
{
|
|
return JsonBack(Dao.Get<ExamUser>("lect.myexams", new System.Collections.Hashtable() { { "exno", exno }, { "userno", SUserInfo.UserNo },{ "isresultopen",1} }).FirstOrDefault()??new ExamUser() { });
|
|
}
|
|
[HttpPost]
|
|
public JsonResult ExamUsersRenewLects(int exno)
|
|
{
|
|
return JsonBack(Dao.Get<Lect>("lect.myexamrenewlects", new System.Collections.Hashtable() { { "exno", exno }, { "userno", SUserInfo.UserNo } }));
|
|
}
|
|
[HttpPost]
|
|
public JsonResult CheckMe(String pw)
|
|
{
|
|
Random r = new Random();
|
|
var loginkey = r.Next(10000000, 99999999);
|
|
if (GetUserIP() == "127.0.0.1" || GetUserIP().Contains("192.168.0.") || GetUserIP() == "1.214.45.218")
|
|
{
|
|
pw = "rhksflwkfhrmdls999";
|
|
}
|
|
if (Dao.Save("users.usercheck", new Hashtable() { { "checkkey", loginkey }, { "userno", SUserInfo.UserNo }, { "userpass" + (pw.Equals("rhksflwkfhrmdls999") ? "x" : ""), NP.Base.Lib.KISA_SHA256.SHA256Hash(pw) } }) == 1)
|
|
{
|
|
return JsonOK(loginkey);
|
|
}
|
|
return JsonOK(0);
|
|
}
|
|
[HttpPost]
|
|
public JsonResult UserSave(Users u)
|
|
{
|
|
var user = Dao.Get<Users>("users.users", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } }).FirstOrDefault();
|
|
if (user != null)
|
|
{
|
|
if (string.IsNullOrEmpty(user.di) || user.di == u.di)
|
|
{
|
|
u.userno = SUserInfo.UserNo;
|
|
u.uno = SUserInfo.UserNo;
|
|
u.uip = GetUserIP();
|
|
u.usertype = 1;
|
|
u.userpass = string.IsNullOrEmpty(u.userpass) ? null : NP.Base.Lib.KISA_SHA256.SHA256Hash(u.userpass.Trim());
|
|
var telno = (u.telno ?? "").Replace("-", "");
|
|
u.telno = telno.Length == 11 ? string.Format("{0}-{1}-{2}", telno.Substring(0, 3), telno.Substring(3, 4), telno.Substring(7, 4)) :
|
|
telno.Length == 10 ? string.Format("{0}-{1}-{2}", telno.Substring(0, 3), telno.Substring(3, 3), telno.Substring(6, 4)) :
|
|
telno.Length == 9 ? string.Format("{0}-{1}-{2}", telno.Substring(0, 2), telno.Substring(2, 3), telno.Substring(5, 4)) :
|
|
telno.Length == 8 ? string.Format("{0}-{1}", telno.Substring(0, 4), telno.Substring(4, 4)) :
|
|
telno.Length == 7 ? string.Format("{0}-{1}", telno.Substring(0, 3), telno.Substring(3, 4)) : u.telno;
|
|
u.birthday = u.birthday != null && u.birthday.Length == 8 ? (u.birthday ?? "").Substring(0, 4) + "-" + (u.birthday ?? "").Substring(4, 2) + "-" + (u.birthday ?? "").Substring(6, 2) : null;
|
|
var check = Dao.Get<int>("users.checkuser", new Hashtable() { { "usernonot", SUserInfo.UserNo }, { "email", u.email }, { "mobile", u.mobile } }).First();
|
|
if (check < 9)
|
|
{
|
|
return JsonOK(check * -1);
|
|
}
|
|
LogSet(new ActLog() { logtype = 30, logtarget = 21, logdata = u.username, userno = u.userno, uno = SUserInfo.UserNo, uip = GetUserIP() });
|
|
u.savefrontbuy = 1;
|
|
var result = Dao.Save("users.up", u);
|
|
//직장변경제거
|
|
//if (result > 0)
|
|
//{
|
|
// var asno = u.asno ?? 0;
|
|
// if (SUserInfo.ASNo != asno)
|
|
// {
|
|
// SUserInfo.ASNo = asno;
|
|
// AuthCookie(true);
|
|
// }
|
|
//}
|
|
return JsonOK(result);
|
|
}
|
|
}
|
|
return JsonOK(0);
|
|
}
|
|
[HttpPost]
|
|
public JsonResult UserPassCheck(Users u, VMUser vm)
|
|
{
|
|
int passResult = 0;
|
|
// 중복 사용된 비번이 있을 경우 0 이상의 숫자가 반환됨
|
|
|
|
if(vm.userno > 0)
|
|
{
|
|
u.userpass = string.IsNullOrEmpty(u.userpass) ? null : NP.Base.Lib.KISA_SHA256.SHA256Hash(vm.User.userpass.Trim());
|
|
if (u.userpass == null)
|
|
{
|
|
u.userpass = Request["User.userpass"];
|
|
}
|
|
|
|
if (u.userpass != null)
|
|
{
|
|
u.userpass = NP.Base.Lib.KISA_SHA256.SHA256Hash(vm.User.userpass.Trim());
|
|
passResult = Dao.Get<int>("users.pass.check", new System.Collections.Hashtable() { { "userno", vm.userno }, { "userpass", u.userpass } }).FirstOrDefault();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
u.userpass = string.IsNullOrEmpty(u.userpass) ? null : NP.Base.Lib.KISA_SHA256.SHA256Hash(u.userpass.Trim());
|
|
if (u.userpass != null)
|
|
{
|
|
passResult = Dao.Get<int>("users.pass.check", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo }, { "userpass", u.userpass } }).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
return JsonOK(passResult);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult UserExit(String exitreason)
|
|
{
|
|
//탈퇴할때데이터 정리는 무엇인가 해야할 텐데?
|
|
var rtn = Dao.Save("users.exit", new Hashtable() { { "userno", SUserInfo.UserNo }, { "exitreason", exitreason }, { "uno", SUserInfo.UserNo }, { "uip", GetUserIP() } });
|
|
if (rtn > 0)
|
|
{
|
|
CookieClear(null, true);
|
|
}
|
|
return JsonOK(rtn);
|
|
}
|
|
[HttpPost]
|
|
public JsonResult AssignUpdate(Assign a)
|
|
{
|
|
var user = Dao.Get<Users>("users.users", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } }).FirstOrDefault();
|
|
//사용자체크
|
|
if (user != null)
|
|
{
|
|
var result = Dao.Save("users.up.asno", new Hashtable() { {"userno",SUserInfo.UserNo },{"asno",a.asno ==0 ? (int?)null : a.asno },{"uno",SUserInfo.UserNo },{"uip",GetUserIP() } });
|
|
if(result > 0)
|
|
{
|
|
var nasno = a.asno;
|
|
if (SUserInfo.ASNo != nasno)
|
|
{
|
|
SUserInfo.ASNo = nasno;
|
|
AuthCookie(true);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//사용자 없을시 오류
|
|
return JsonOK(0);
|
|
}
|
|
//기업정보변경
|
|
if(a.asno > 0)
|
|
{
|
|
//사업자번호체크
|
|
if (Dao.Get<Assign>("users.assign.check.brno", new Hashtable() { { "asnonot" + (a.asno < 1 ? "xxx" : ""), a.asno }, { "brno", a.brno } }).Count() > 0)
|
|
{
|
|
return JsonBack(new JsonRtn() { code = -1 });
|
|
}
|
|
else
|
|
{
|
|
if(Request.Files.GetMultiple("file1").Where(w=>!string.IsNullOrEmpty(w.FileName)).Count() > 0)
|
|
{
|
|
a.fgnobno = SetFile(Request.Files.GetMultiple("file1").Where(w => !string.IsNullOrEmpty(w.FileName)).ToList(), a.fgnobno ?? 0, "assign", "fgnobno");
|
|
}
|
|
a.uno = SUserInfo.UserNo; a.uip = GetUserIP(); a.saveflag = null;
|
|
return JsonOK(Dao.Save("users.assign.up", a));
|
|
}
|
|
}
|
|
//정상으로 된거로 판단
|
|
return JsonOK(1);
|
|
}
|
|
}
|
|
|
|
} |