Ejemplo n.º 1
0
        public ActionResult Login(UserValidate user)
        {
            if (ModelState.IsValid)
            {
                // Db
                using (wenevaescapeEntities db = new wenevaescapeEntities())
                {
                    var EncryptedUsersPassword = EncryptS.Hash(user.loginPassword);
                    var xUser = db.Users.Where(x => x.username == user.loginUsername && x.password == EncryptedUsersPassword).FirstOrDefault();
                    if (xUser != null)
                    {
                        Session["ID"]       = xUser.id;
                        Session["Username"] = xUser.username;
                        Session["Role"]     = xUser.role;
                        switch (xUser.role.ToString())
                        {
                        //admin
                        case "1":
                            return(RedirectToAction("Index", "Home"));

                        //other
                        default:
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    ViewBag.LoginError = "Wrong username or password.";
                    return(View("LoginPage", new UserValidate()));
                }
            }
            return(RedirectToAction("LoginPage", new UserValidate()));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateUser(String id)
        {
            var          user    = db.NhanViens.Where(n => n.MaNhanVien == id).FirstOrDefault();
            UserValidate userVal = new UserValidate();

            userVal.MaNhanVien = user.MaNhanVien;
            userVal.HoTen      = user.HoTen;
            userVal.MatKhau    = user.MatKhau;
            userVal.GioiTinh   = user.GioiTinh;

            userVal.MaChucVuNV   = user.MaChucVuNV;
            userVal.QueQuan      = user.QueQuan;
            userVal.HinhAnh      = user.HinhAnh;
            userVal.DanToc       = user.DanToc;
            userVal.sdt_NhanVien = user.sdt_NhanVien;
            userVal.MaHopDong    = user.MaHopDong;

            userVal.NgaySinh        = user.NgaySinh;
            userVal.TrangThai       = user.TrangThai;
            userVal.MaChuyenNganh   = user.MaChuyenNganh;
            userVal.MaTrinhDoHocVan = user.MaTrinhDoHocVan;
            userVal.MaPhongBan      = user.MaPhongBan;

            userVal.CMND           = user.CMND;
            userVal.XacNhanMatKhau = user.MatKhau;

            return(View(userVal));
            //  return View(user);
        }
Ejemplo n.º 3
0
        public IHttpActionResult PostLogin(String username, String password, UserValidate userValidate)
        {
            Console.WriteLine("User validate: " + userValidate.Password + "-" + userValidate.Username);
            Login             login     = new Login();
            LoginResponse     response  = new LoginResponse();
            IQueryable <User> userFound = db.User.Where(
                user =>
                (user.Username == userValidate.Username) && (user.Password == userValidate.Password)
                );
            List <User> listUser = userFound.ToList <User>();

            /*
             * if(listUser.Count != 1)
             * {
             *  throw new MTException {
             *      Code = "666",
             *      Name = "INVALID_USER",
             *      Value = "Usuario o contrasenia incorrecta"
             *  };
             * }*/
            listUser.ForEach(delegate(User user)
            {
                response.Error  = "0";
                response.Rol    = db.Rol.Find(user.RolId).Name;
                response.Status = "ok";
            });
            return(Ok(response));
        }
Ejemplo n.º 4
0
        public async Task Invoke(HttpContext context)
        {
            string authHeader = context.Request.Headers["Authorization"];

            if (authHeader != null && authHeader.StartsWith("Basic"))
            {
                //Extract credentials
                string   encodedUsernamePassword = authHeader.Substring("Basic ".Length).Trim();
                Encoding encoding         = Encoding.GetEncoding("iso-8859-1");
                string   usernamePassword = encoding.GetString(Convert.FromBase64String(encodedUsernamePassword));

                int seperatorIndex = usernamePassword.IndexOf(':');

                var username = usernamePassword.Substring(0, seperatorIndex);
                var password = usernamePassword.Substring(seperatorIndex + 1);

                if (UserValidate.Login(username, password))
                {
                    await _next.Invoke(context);
                }
                else
                {
                    context.Response.StatusCode = 401; //Unauthorized
                    return;
                }
            }
            else
            {
                // no authorization header
                context.Response.StatusCode = 401; //Unauthorized
                return;
            }
        }
Ejemplo n.º 5
0
        public string LoginValidate(string token)
        {
            string result = "";

            try
            {
                var json = u_JurisdictionUtils.UserValidationApi(token);
                UserValidateResult userValidateResult = JsonConvert.DeserializeObject <UserValidateResult>(json);
                UserValidate       userValidate       = userValidateResult.uservaliDate;

                SessionUtils.Add("userCode", userValidate.UserCode);
                SessionUtils.Add("departmentId", userValidate.DepartmentId);
                SessionUtils.Add("token", token);
                SessionUtils.Add("token_r", userValidate.Token_R);

                string responsibleDepartment = u_JurisdictionUtils.ResponsibleDepartmentApi(userValidate.Token_R, userValidate.UserCode);  ///负责部门
                if (u_TypeJudgmentUtils.IsNullOrEmptyObj(responsibleDepartment) == false)
                {
                    SessionUtils.Add("responsibleDepartment", responsibleDepartment);
                }
            }
            catch (Exception ex)
            {
                result = "{\"code\":\"0\",\"msg\":\"后台出错" + ex + "\"}";
            }
            return(result);
        }
Ejemplo n.º 6
0
        public ActionResult UpDateUser()
        {
            UserValidate up = new UserValidate();
            var          id = Session["MaNhanVien"] as String;
            var          us = db.NhanViens.Where(n => n.MaNhanVien == id).FirstOrDefault();

            if (us != null)
            {
                up.MaNhanVien      = us.MaNhanVien;
                up.HinhAnh         = us.HinhAnh;
                up.MatKhau         = us.MatKhau;
                up.XacNhanMatKhau  = us.MatKhau;
                up.HoTen           = us.HoTen;
                up.NgaySinh        = us.NgaySinh;
                up.QueQuan         = us.QueQuan;
                up.GioiTinh        = us.GioiTinh;
                up.DanToc          = us.DanToc;
                up.sdt_NhanVien    = us.sdt_NhanVien;
                up.MaChuyenNganh   = us.MaChuyenNganh;
                up.MaTrinhDoHocVan = us.MaTrinhDoHocVan;
                up.CMND            = us.CMND;

                return(View(up));
            }
            return(Redirect("~/"));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 查询停封玩家信息
        /// </summary>
        /// <param name="index">第几页</param>
        /// <param name="pageSize">每页记录数</param>
        /// <returns></returns>
        public Message Soccer_AccountState_Query(int index, int pageSize)
        {
            System.Data.DataSet ds = null;
            string serverIP        = null;
            string str_type        = "";
            string str_string      = "";

            try
            {
                serverIP   = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.Soccer_ServerIP).m_bValueBuffer);
                str_type   = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.Soccer_Type).m_bValueBuffer);
                str_string = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.Soccer_String).m_bValueBuffer);

                SqlHelper.log.WriteLog(lg.API_Display + lg.Soccer_Soccer + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.Soccer_CharacterInfoAPI_Account + str_string + lg.Soccer_CharacterInfoAPI_BanInfo);
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.Soccer_Soccer + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.Soccer_CharacterInfoAPI_Account + str_string + lg.Soccer_CharacterInfoAPI_BanInfo);

                ds = SOCCERCharacterInfo.Soccer_AccountState_Query(serverIP, str_type, str_string);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    //总页数
                    int pageCount = 0;
                    pageCount = ds.Tables[0].Rows.Count % pageSize;
                    if (pageCount > 0)
                    {
                        pageCount = ds.Tables[0].Rows.Count / pageSize + 1;
                    }
                    else
                    {
                        pageCount = ds.Tables[0].Rows.Count / pageSize;
                    }
                    if (index + pageSize > ds.Tables[0].Rows.Count)
                    {
                        pageSize = ds.Tables[0].Rows.Count - index;
                    }
                    Query_Structure[] structList = new Query_Structure[pageSize];
                    for (int i = index; i < index + pageSize; i++)
                    {
                        Query_Structure strut = new Query_Structure((uint)ds.Tables[0].Rows[i].ItemArray.Length + 1);
                        byte[]          bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[0]));
                        strut.AddTagKey(TagName.Soccer_loginId, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[1]));
                        strut.AddTagKey(TagName.Soccer_regDate, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[2]));
                        strut.AddTagKey(TagName.Soccer_m_id, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        strut.AddTagKey(TagName.PageCount, TagFormat.TLV_INTEGER, 4, TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, pageCount));
                        structList[i - index] = strut;
                    }
                    return(Message.COMMON_MES_RESP(structList, Msg_Category.SOCCER_ADMIN, ServiceKey.SOCCER_ACCOUNTSTATE_QUERY_RESP, 4));
                }
                else
                {
                    return(Message.COMMON_MES_RESP(lg.Soccer_CharacterInfoAPI_NoBan, Msg_Category.SOCCER_ADMIN, ServiceKey.SOCCER_ACCOUNTSTATE_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
                }
            }
            catch (System.Exception ex)
            {
                return(Message.COMMON_MES_RESP(ex.Message, Msg_Category.SOCCER_ADMIN, ServiceKey.SOCCER_ACCOUNTSTATE_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
            }
        }
Ejemplo n.º 8
0
        private void SendMail(User u, UserValidate uv)
        {
            string link = string.Format("http://{0}{1}", HttpContext.Current.Request.Url.Authority,
                                        UrlTo <UserController>(p => p.Active(uv.SerializeToString())));
            string mail = string.Format("请点击以下链接或复制链接到浏览器里以完成用户注册:<br/>\n<a href=\"{0}\">{0}</a>", link);

            CommonHelper.SendMail(u.Email, mail);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 查看玩家身上道具
        /// </summary>
        /// <returns></returns>
        public Message itemShop_Owner_Query()
        {
            string  serverIP = null;
            string  userID   = null;
            DataSet ds       = null;

            try
            {
                serverIP = Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_ServerIP).m_bValueBuffer);
                userID   = Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_UserID).m_bValueBuffer);
                SqlHelper.log.WriteLog(lg.API_Display + lg.O2JAM2API_BAF + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.O2JAM2API_AccountInfoAPI_Account + userID + lg.O2JAM2API_ItemShopAPI_AllBodyItem);
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.O2JAM2API_BAF + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.O2JAM2API_AccountInfoAPI_Account + userID + lg.O2JAM2API_ItemShopAPI_AllBodyItem);
                //请求玩家身上的道具
                ds = ItemShopInfo.AvatarItemList_Query(serverIP, userID);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    Query_Structure[] structList = new Query_Structure[ds.Tables[0].Rows.Count];
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Query_Structure strut = new Query_Structure((uint)ds.Tables[0].Rows[i].ItemArray.Length);
                        //道具编号
                        byte[] bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[0]);
                        strut.AddTagKey(TagName.O2JAM2_ItemCode, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        //道具名
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[1]));
                        strut.AddTagKey(TagName.O2JAM2_ItemName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        //最小等级
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[2]);
                        strut.AddTagKey(TagName.O2JAM2_Level, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        //道具位置
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[3]);
                        strut.AddTagKey(TagName.O2JAM2_Position, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        //道具使用次数
                        int timelimits = Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[4]);
                        if (timelimits == -1)
                        {
                            timelimits = 0;
                        }
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, timelimits);
                        strut.AddTagKey(TagName.O2JAM2_Timeslimt, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        //道具时间限制
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_TIMESTAMP, ds.Tables[0].Rows[i].ItemArray[5]);
                        strut.AddTagKey(TagName.O2JAM2_DateLimit, TagFormat.TLV_TIMESTAMP, (uint)bytes.Length, bytes);
                        structList[i] = strut;
                    }
                    return(Message.COMMON_MES_RESP(structList, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_AVATORLIST_QUERY_RESP, 6));
                }
                else
                {
                    return(Message.COMMON_MES_RESP(lg.O2JAM2API_ItemShopAPI_NoBodyItem, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_AVATORLIST_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(Message.COMMON_MES_RESP(lg.O2JAM2API_AccountInfoAPI_NoAccount, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_AVATORLIST_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
            }
        }
Ejemplo n.º 10
0
        public ActionResult UpdateUser(UserValidate upUser)
        {
            upUser.XacNhanMatKhau = upUser.MatKhau;
            var us = db.NhanViens.Where(n => n.MaNhanVien == upUser.MaNhanVien).FirstOrDefault();

            if (ModelState.IsValid)
            {
                //var us = db.NhanViens.Where(n => n.MaNhanVien == upUser.MaNhanVien).FirstOrDefault();
                if (us != null)
                {
                    CapNhatTrinhDoHocVan capNhat = new CapNhatTrinhDoHocVan();
                    capNhat.MaNhanVien       = upUser.MaNhanVien;
                    capNhat.NgayCapNhat      = DateTime.Now.Date;
                    capNhat.MaTrinhDoTruoc   = us.MaTrinhDoHocVan;
                    capNhat.MaTrinhDoCapNhat = upUser.MaTrinhDoHocVan;

                    us.MaNhanVien = upUser.MaNhanVien;
                    us.HoTen      = upUser.HoTen;
                    us.MatKhau    = upUser.MatKhau;
                    us.GioiTinh   = upUser.GioiTinh;

                    us.MaChucVuNV   = upUser.MaChucVuNV;
                    us.QueQuan      = upUser.QueQuan;
                    us.HinhAnh      = upUser.HinhAnh;
                    us.DanToc       = upUser.DanToc;
                    us.sdt_NhanVien = upUser.sdt_NhanVien;
                    us.MaHopDong    = upUser.MaHopDong;

                    us.NgaySinh        = upUser.NgaySinh;
                    us.TrangThai       = upUser.TrangThai;
                    us.MaChuyenNganh   = upUser.MaChuyenNganh;
                    us.MaTrinhDoHocVan = upUser.MaTrinhDoHocVan;
                    us.MaPhongBan      = upUser.MaPhongBan;
                    us.CMND            = upUser.CMND;

                    var trinhdo = db.TrinhDoHocVans.Where(n => n.MaTrinhDoHocVan.Equals(us.MaTrinhDoHocVan)).FirstOrDefault();

                    var luong = db.Luongs.Where(n => n.MaNhanVien.Equals(us.MaNhanVien)).FirstOrDefault();

                    if (trinhdo.HeSoBac != null)
                    {
                        luong.HeSoLuong = luong.HeSoLuong < (double)trinhdo.HeSoBac ? (double)trinhdo.HeSoBac : luong.HeSoLuong;
                    }
                    else
                    {
                        luong.HeSoLuong = 1;
                    }



                    db.CapNhatTrinhDoHocVans.Add(capNhat);

                    db.SaveChanges();
                    return(Redirect("/admin/quan-ly-nhan-vien"));
                }
            }
            return(View(upUser));
        }//end update
 public void ReclickCreate(String ClickUserLink, String ElementVisible, String ClickElement, String ActualPage, IWebDriver driver, String AssertText)
 {
     UserValidate = new UserValidate(driver);
     new UsersReusables(driver).UsersNavigate(ClickUserLink);
     UserValidate.WaitElementVisible(ElementVisible);
     new UsersReusables(driver).UsersNavigate(ClickElement);
     UserValidate.WaitPageLoad(ActualPage);
     UserValidate.PageContainsText(driver, AssertText);
 }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            //If the Authorization header is empty or null
            //then return Unauthorized
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request
                                         .CreateResponse(HttpStatusCode.Unauthorized);

                // If the request was unauthorized, add the WWW-Authenticate header
                // to the response which indicates that it require basic authentication
                if (actionContext.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    actionContext.Response.Headers.Add("WWW-Authenticate",
                                                       string.Format("Basic realm=\"{0}\"", Realm));
                }
            }
            else
            {
                //Get the authentication token from the request header
                string authenticationToken = actionContext.Request.Headers
                                             .Authorization.Parameter;

                //Decode the string
                string decodedAuthenticationToken = Encoding.UTF8.GetString(
                    Convert.FromBase64String(authenticationToken));

                //Convert the string into an string array
                string[] usernamePasswordArray = decodedAuthenticationToken.Split(':');

                //First element of the array is the username
                string username = usernamePasswordArray[0];

                //Second element of the array is the password
                string password = usernamePasswordArray[1];

                UserValidate validator = new UserValidate();
                //call the login method to check the username and password
                if (validator.ValidateUser(username, password))
                {
                    var identity = new GenericIdentity(username);

                    IPrincipal principal = new GenericPrincipal(identity, null);
                    Thread.CurrentPrincipal = principal;

                    if (HttpContext.Current != null)
                    {
                        HttpContext.Current.User = principal;
                    }
                }
                else
                {
                    actionContext.Response = actionContext.Request
                                             .CreateResponse(HttpStatusCode.Unauthorized);
                }
            }
        }
        /// <summary>
        /// 玩家上线、下线时间查询
        /// </summary>
        /// <returns></returns>
        public Message CR_Login_Logout_Query()
        {
            System.Data.DataSet ds = null;
            string serverIP        = null;
            string userID          = "";
            string nickName        = "";
            int    actionType      = 0;

            try
            {
                serverIP = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_ServerIP).m_bValueBuffer);
                TLV_Structure strut1 = new TLV_Structure(TagName.CR_ACTION, 4, msg.m_packet.m_Body.getTLVByTag(TagName.CR_ACTION).m_bValueBuffer);
                actionType = (int)strut1.toInteger();
                if (actionType == 1)
                {
                    userID = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_UserID).m_bValueBuffer);
                }
                else if (actionType == 2)
                {
                    nickName = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_NickName).m_bValueBuffer);
                }
                SqlHelper.log.WriteLog(lg.API_Display + lg.CR_CR + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.CR_AccountInfoAPI_Account + userID + lg.CR_CharacterInfoAPI_OnlineStatus);
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.CR_CR + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.CR_AccountInfoAPI_Account + userID + lg.CR_CharacterInfoAPI_OnlineStatus);
                ds = CRCharacterInfo.CR_Login_Logout_Query(serverIP, userID, nickName, actionType);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    Query_Structure[] structList = new Query_Structure[ds.Tables[0].Rows.Count];
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Query_Structure strut = new Query_Structure((uint)ds.Tables[0].Rows[i].ItemArray.Length);
                        byte[]          bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[0]));
                        strut.AddTagKey(TagName.CR_UserName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[1]));
                        strut.AddTagKey(TagName.CR_NickName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_TIMESTAMP, Convert.ToDateTime(ds.Tables[0].Rows[i].ItemArray[2]));
                        strut.AddTagKey(TagName.CR_Last_Login, TagFormat.TLV_TIMESTAMP, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_TIMESTAMP, Convert.ToDateTime(ds.Tables[0].Rows[i].ItemArray[3]));
                        strut.AddTagKey(TagName.CR_Last_Logout, TagFormat.TLV_TIMESTAMP, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[4]));
                        strut.AddTagKey(TagName.CR_Last_Playing_Time, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[5]));
                        strut.AddTagKey(TagName.CR_Total_Time, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        structList[i] = strut;
                    }
                    return(Message.COMMON_MES_RESP(structList, Msg_Category.CR_ADMIN, ServiceKey.CR_LOGIN_LOGOUT_QUERY_RESP, 6));
                }
                else
                {
                    return(Message.COMMON_MES_RESP(lg.CR_AccountInfoAPI_NoAccount, Msg_Category.CR_ADMIN, ServiceKey.CR_LOGIN_LOGOUT_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
                }
            }
            catch (System.Exception)
            {
                return(Message.COMMON_MES_RESP(lg.CR_AccountInfoAPI_NoAccount, Msg_Category.CR_ADMIN, ServiceKey.CR_LOGIN_LOGOUT_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="name">姓名</param>
        /// <param name="pwd">密码</param>
        /// <returns>成功返回对象 否则返回null</returns>
        public bool Login(string name, string pwd)
        {
            //用户输入的过滤
            var user = UserValidate.GetUser(name, pwd);

            if (user == null)
            {
                return(false);
            }
            this.User = user;
            return(true);
        }
Ejemplo n.º 15
0
 public PasswordTests()
 {
     _userValidate = new UserValidate(new List <ISpec>
     {
         new HasCharNotNullSpec(),
         new HasLowerCharSpec(),
         new HasMinMaxCharsSpec(),
         new HasNumberSpec(),
         new HasSymbolsSpec(),
         new HasUpperCharSpec(),
         new RepeatedCharacterSpec()
     });
 }
Ejemplo n.º 16
0
        public LoginResponse PostLogin([FromBody] UserValidate userValidate)
        {
            if (!ModelState.IsValid)
            {
                throw new MTException
                      {
                          Code  = "666",
                          Name  = "INVALID_USER",
                          Value = "Usuario o contrasenia incorrecta"
                      };
            }
            Console.WriteLine("User validate: " + userValidate.Password + "-" + userValidate.Username);
            Login             login     = new Login();
            LoginResponse     response  = new LoginResponse();
            IQueryable <User> userFound = db.User.Where(
                user =>
                (user.Username == userValidate.Username) && (user.Password == userValidate.Password)
                );
            List <User> listUser = userFound.ToList <User>();

            if (listUser.Count != 1)
            {
                MTException mtx = new MTException
                {
                    Code  = "666",
                    Name  = "INVALID_USER",
                    Value = "Usuario o contrasenia incorrecta"
                };
                throw mtx;
            }
            listUser.ForEach(delegate(User user)
            {
                response.Error    = "0";
                response.Rol      = db.Rol.Find(user.RolId).Name;
                response.Status   = "ok";
                response.UserId   = user.UserId;
                response.Username = user.Username;
                login.UserId      = user.UserId;
                login.Status      = "ok";
                login.Rol         = db.Rol.Find(user.RolId).Name;
                login.TimeOut     = 360;
            });

            // db.Login.Add(login);
            // db.SaveChanges();
            // return CreatedAtRoute("DefaultApi", new { id = login.LoginId }, login);
            return(response);
        }
Ejemplo n.º 17
0
        public string Active(string validateText)
        {
            var uv = UserValidate.DeserializeFromString(validateText);

            if (uv != null && uv.Mode == 'a')
            {
                uv.User.Role = UserRole.User;
                uv.User.Save();
                Flash.Notice = "用户激活成功";
            }
            else
            {
                Flash.Notice = "用户激活失败";
            }
            return(UrlTo <ArticleController>());
        }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response =
                    actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);

                if (actionContext.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    actionContext.Response.Headers.Add("WWW-Authrnticate", string.Format("Basic realm=\"{0}\"", Realm));
                }
            }
            else
            {
                string authenticationToken = actionContext.Request.Headers
                                             .Authorization.Parameter;

                string decodeAuthenticationToken =
                    Encoding.UTF8.GetString(Convert.FromBase64String(authenticationToken));

                string[] usernamePasswordArray = decodeAuthenticationToken.Split(':');

                string username = usernamePasswordArray[0];

                string password = usernamePasswordArray[1];

                if (UserValidate.Login(username, password))
                {
                    var identity = new GenericIdentity(username);

                    IPrincipal principal = new GenericPrincipal(identity, null);

                    Thread.CurrentPrincipal = principal;

                    if (HttpContext.Current != null)
                    {
                        HttpContext.Current.User = principal;
                    }
                }
                else
                {
                    actionContext.Response = actionContext.Request.
                                             CreateResponse(HttpStatusCode.Unauthorized);
                }
            }
        }
Ejemplo n.º 19
0
        public string SendActiveMail()
        {
            var u = this.GetLoginUser();

            if (u.Role == UserRole.NonactivatedUser)
            {
                var uv = UserValidate.FindOne(p => p.UserId == u.Id);
                if (uv == null)
                {
                    uv = new UserValidate().Init(u.Id);
                    uv.Save();
                }
                uv.Mode = 'a';
                SendMail(u, uv);
                Flash.Notice = "激活邮件发送成功";
            }
            return(UrlTo <UserController>(p => p.Profile()));
        }
        // OAuthAuthorizationServerProvider sınıfının kaynak erişimine izin verebilmek için ilgili GrantResourceOwnerCredentials metotunu override ediyoruz.
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            // CORS ayarlarını set ediyoruz.
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            // Kullanıcının access_token alabilmesi için gerekli validation işlemlerini yapıyoruz.
            Kullanicilar kullanici = UserValidate.Validate(context.UserName, context.Password);

            if (kullanici != null)
            {
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim("ID", kullanici.ID.ToString()));
                identity.AddClaim(new Claim(ClaimTypes.Role, kullanici.KullaniciTipi.ToString()));

                context.Validated(identity);
            }
            else
            {
                context.SetError("invalid_grant", "Kullanıcı adı veya şifre yanlış.");
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 查询所有的技能道具
        /// </summary>
        /// <returns></returns>
        public Message Soccer_Item_Skill_Blur_Query()
        {
            System.Data.DataSet ds = null;
            int    item_type       = 1;
            string Content         = null;

            try
            {
                SqlHelper.log.WriteLog("劲爆足球+>" + "查询所有道具!");
                Console.WriteLine(DateTime.Now + " - 劲爆足球+>服务器地址" + "查询所有道具!");
                Content = Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.Soccer_content).m_bValueBuffer);
                ds      = SOCCERItemShopInfo.Soccer_Item_Skill_Blur_Query(item_type, Content);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    Query_Structure[] structList = new Query_Structure[ds.Tables[0].Rows.Count];
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Query_Structure strut1 = new Query_Structure((uint)ds.Tables[0].Rows[i].ItemArray.Length);
                        byte[]          bytes  = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]));
                        strut1.AddTagKey(TagName.Soccer_idx, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[1]));
                        strut1.AddTagKey(TagName.Soccer_i_name, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[i].ItemArray[2]));
                        strut1.AddTagKey(TagName.Soccer_body_part, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[3]));
                        strut1.AddTagKey(TagName.Soccer_item_type, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        structList[i] = strut1;
                    }
                    return(Message.COMMON_MES_RESP(structList, Msg_Category.SOCCER_ADMIN, ServiceKey.SOCCER_ITEM_SKILL_BLUR_QUERY_RESP, 4));
                }
                else
                {
                    return(Message.COMMON_MES_RESP("没有道具列表!", Msg_Category.SOCCER_ADMIN, ServiceKey.SOCCER_ITEM_SKILL_BLUR_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
                }
            }
            catch (System.Exception ex)
            {
                return(Message.COMMON_MES_RESP("没有道具列表!", Msg_Category.SOCCER_ADMIN, ServiceKey.SOCCER_ITEM_SKILL_BLUR_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
            }
        }
Ejemplo n.º 22
0
        public ActionResult UpDateUser(UserValidate us, HttpPostedFileBase HinhAnh)
        {
            if (ModelState.IsValid)
            {
                var up = db.NhanViens.Where(n => n.MaNhanVien == us.MaNhanVien).FirstOrDefault();
                up.MaNhanVien = us.MaNhanVien;

                up.MatKhau         = us.MatKhau;
                up.MatKhau         = us.XacNhanMatKhau;
                up.HoTen           = us.HoTen;
                up.NgaySinh        = us.NgaySinh;
                up.QueQuan         = us.QueQuan;
                up.GioiTinh        = us.GioiTinh;
                up.DanToc          = us.DanToc;
                up.sdt_NhanVien    = us.sdt_NhanVien;
                up.MaChuyenNganh   = us.MaChuyenNganh;
                up.MaTrinhDoHocVan = us.MaTrinhDoHocVan;
                up.CMND            = us.CMND;

                if (us.HinhAnh != null)
                {
                    HinhAnh.SaveAs(HttpContext.Server.MapPath("~/Content/images/")
                                   + HinhAnh.FileName);
                    up.HinhAnh = HinhAnh.FileName;
                    us.HinhAnh = HinhAnh.FileName;
                    //user.Image = userVal.Image;
                }
                else
                {
                    us.HinhAnh = up.HinhAnh;
                }

                db.SaveChanges();
                return(View(us));
            }
            else
            {
                return(View(us));
            }
        }
Ejemplo n.º 23
0
 public ActionResult Register(UserValidate user, User xUser)
 {
     if (ModelState.IsValid)
     {
         using (wenevaescapeEntities db = new wenevaescapeEntities())
         {
             if (db.Users.Any(x => x.username == user.registerUsername))
             {
                 ViewBag.RegisterError = "This username has already used.";
                 return(View("LoginPage", new UserValidate()));
             }
             xUser.username = user.registerUsername.ToString();
             xUser.password = EncryptS.Hash(user.registerPassword).ToString();
             xUser.role     = (int)1;
             db.Users.Add(xUser);
             db.Configuration.ValidateOnSaveEnabled = false;
             db.SaveChanges();
             ViewBag.SuccessMessage = "Your account successfully registered.";
             return(View("LoginPage", new UserValidate()));
         }
     }
     return(View("LoginPage", new UserValidate()));
 }
Ejemplo n.º 24
0
        public UserToken UserLogin(User userLogin)
        {
            var userFound = UserValidate.Login(userLogin.UserName, userLogin.Password);

            if (userFound) //Si el usuario ya se encuentra registrado en la base de datos se le daran sus credenciales (Token)
            {
                var userInDB = UserValidate.GetUserDetails(userLogin.UserName, userLogin.Password);

                string encodeString = $"{userLogin.UserName}:{userLogin.Password}";

                UserToken userToken = new UserToken()
                {
                    UserName = userInDB.UserName,
                    Role     = userInDB.Roles,
                    Token    = Convert.ToBase64String(Encoding.UTF8.GetBytes(encodeString))
                };

                return(userToken);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 玩家资料信息查询
        /// </summary>
        /// <returns></returns>
        public Message CR_CharacterInfo_Query()
        {
            System.Data.DataSet ds = null;
            string serverIP        = null;
            string account         = "";
            string nickName        = "";
            int    actionType      = 0;

            try
            {
                serverIP = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_ServerIP).m_bValueBuffer);
                TLV_Structure strut1 = new TLV_Structure(TagName.CR_ACTION, 4, msg.m_packet.m_Body.getTLVByTag(TagName.CR_ACTION).m_bValueBuffer);
                actionType = (int)strut1.toInteger();
                if (actionType == 1)
                {
                    account = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_ACCOUNT).m_bValueBuffer);
                }
                else if (actionType == 2)
                {
                    nickName = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_NickName).m_bValueBuffer);
                }
                SqlHelper.log.WriteLog(lg.API_Display + lg.CR_CR + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.CR_AccountInfoAPI_Account + account + lg.CR_AccountInfoAPI_AccountInfo);
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.CR_CR + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.CR_AccountInfoAPI_Account + account + lg.CR_AccountInfoAPI_AccountInfo);
                ds = CRCharacterInfo.CR_CharacterInfo_Query(serverIP, account, nickName, actionType);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    Query_Structure[] structList = new Query_Structure[ds.Tables[0].Rows.Count];
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Query_Structure strut = new Query_Structure((uint)ds.Tables[0].Rows[i].ItemArray.Length);
                        byte[]          bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[0].ItemArray[0]));
                        strut.AddTagKey(TagName.CR_ACCOUNT, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(ds.Tables[0].Rows[0].ItemArray[1]));
                        strut.AddTagKey(TagName.CR_NickName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[2]));
                        strut.AddTagKey(TagName.CR_PSTID, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[3]));
                        strut.AddTagKey(TagName.CR_EXP, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[4]));
                        strut.AddTagKey(TagName.CR_Money, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[5]));
                        strut.AddTagKey(TagName.CR_RMB, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[6]));
                        strut.AddTagKey(TagName.CR_SEX, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[7]));
                        strut.AddTagKey(TagName.CR_License, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);

                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[8]));
                        strut.AddTagKey(TagName.CR_RaceTotal, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[9]));
                        strut.AddTagKey(TagName.CR_RaceWon, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[10]));
                        strut.AddTagKey(TagName.CR_ExpOrder, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[11]));
                        strut.AddTagKey(TagName.CR_WinRateOrder, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[12]));
                        strut.AddTagKey(TagName.CR_WinNumOrder, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        structList[i] = strut;
                    }
                    return(Message.COMMON_MES_RESP(structList, Msg_Category.CR_ADMIN, ServiceKey.CR_CHARACTERINFO_QUERY_RESP, 13));
                }
                else
                {
                    return(Message.COMMON_MES_RESP(lg.CR_AccountInfoAPI_NoAccount, Msg_Category.CR_ADMIN, ServiceKey.CR_CHARACTERINFO_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
                }
            }
            catch (System.Exception)
            {
                return(Message.COMMON_MES_RESP(lg.CR_AccountInfoAPI_NoAccount, Msg_Category.CR_ADMIN, ServiceKey.CR_CHARACTERINFO_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
            }
        }
Ejemplo n.º 26
0
        public ActionResult ThemUser(UserValidate nv)
        {
            nv.XacNhanMatKhau = nv.MatKhau;
            if (ModelState.IsValid)
            {
                ViewBag.err = String.Empty;
                var checkMaNhanVien = db.NhanViens.Any(x => x.MaNhanVien == nv.MaNhanVien);

                if (checkMaNhanVien)
                {
                    ViewBag.err = "tài khoản đã tồn tại";
                    //ModelState.AddModelError("MaNhanVien", "Mã tài khoản đã tồn tại");
                    return(View(nv));
                }
                else
                {
                    Luong    luong = new Luong();
                    HopDong  hd    = new HopDong();
                    NhanVien nvAdd = new NhanVien();
                    nvAdd.MaNhanVien      = nv.MaNhanVien;
                    nvAdd.MatKhau         = nv.MatKhau;
                    nvAdd.HoTen           = nv.HoTen;
                    nvAdd.NgaySinh        = nv.NgaySinh;
                    nvAdd.QueQuan         = nv.QueQuan;
                    nvAdd.GioiTinh        = nv.GioiTinh;
                    nvAdd.DanToc          = nv.DanToc;
                    nvAdd.MaChucVuNV      = nv.MaChucVuNV;
                    nvAdd.MaPhongBan      = nv.MaPhongBan;
                    nvAdd.MaChuyenNganh   = nv.MaChuyenNganh;
                    nvAdd.MaTrinhDoHocVan = nv.MaTrinhDoHocVan;
                    nvAdd.MaHopDong       = nv.MaNhanVien;
                    nvAdd.TrangThai       = true;
                    nvAdd.HinhAnh         = "icon.jpg";

                    //add hop dong
                    hd.MaHopDong  = nv.MaNhanVien;
                    hd.NgayBatDau = DateTime.Now.Date;

                    //tao bang luong
                    luong.MaNhanVien    = nv.MaNhanVien;
                    luong.LuongToiThieu = 1150000;
                    luong.BHXH          = 8;
                    luong.BHYT          = 1.5;
                    luong.BHTN          = 1;
                    var trinhdo = db.TrinhDoHocVans.Where(n => n.MaTrinhDoHocVan.Equals(nv.MaTrinhDoHocVan)).FirstOrDefault();
                    var chucvu  = db.ChucVuNhanViens.Where(n => n.MaChucVuNV.Equals(nv.MaChucVuNV)).SingleOrDefault();

                    if (trinhdo.MaTrinhDoHocVan.Equals(nv.MaTrinhDoHocVan))
                    {
                        luong.HeSoLuong = (double)trinhdo.HeSoBac;
                    }


                    if (chucvu.MaChucVuNV.Equals(nv.MaChucVuNV))
                    {
                        if (chucvu.HSPC != null)
                        {
                            luong.PhuCap = (double)chucvu.HSPC;
                        }
                        else
                        {
                            luong.PhuCap = 0;
                        }
                    }



                    // tmp.Image = "~/Content/images/icon.jpg";
                    db.NhanViens.Add(nvAdd);
                    db.HopDongs.Add(hd);

                    db.Luongs.Add(luong);
                    // @ViewBag.add = "Đăng ký thành công";
                    db.SaveChanges();
                    //xác thực tài khoản trong ứng dụng
                    FormsAuthentication.SetAuthCookie(nvAdd.MaNhanVien, false);
                    //trả về trang quản lý

                    return(Redirect("/admin/quan-ly-nhan-vien"));
                }
            }
            else
            {
                return(View(nv));
            }
        }//end add nhan vien
Ejemplo n.º 27
0
 public ActionResult LogOn(UserValidate uv)
 {
     if (!ModelState.IsValid)
     {
         return(View(uv));
     }
     else
     {
         RollCallDataContext dc = new RollCallDataContext();
         // 验证用户身份
         if (uv.Identity == "Student")
         {
             var student = dc.Student.SingleOrDefault(t => t.No.ToString() == uv.UserName);
             if (student != null && WordsIndex.getWordsIndex(student.Name).ToLower() == uv.Password)
             {
                 // 学生身份验证通过
                 addCookie(student.Name + "同学", "Student", uv.RememberMe);
                 Session["StudentNo"] = uv.UserName;
                 return(RedirectToAction("MyClasses", "RollCall", new { id = uv.UserName }));
             }
         }
         else if (uv.Identity == "Teacher")
         {
             foreach (ClassInfo ci in dc.ClassInfo)
             {
                 if (WordsIndex.getWordsIndex(ci.ClassName).ToLower() == uv.UserName)
                 {
                     foreach (Course course in dc.Course.Where(t => t.ClassID == ci.ID))
                     {
                         if (WordsIndex.getWordsIndex(course.CourseName).ToLower() == uv.Password)
                         {
                             // 教师身份登录
                             addCookie(ci.ClassName + "的" + course.CourseName + "老师", "Teacher", uv.RememberMe);
                             Session["ClassID"]  = ci.ID;
                             Session["CourseID"] = course.ID;
                             return(RedirectToAction("Index", "Teacher", new { id = ci.ID, id2 = course.ID }));
                         }
                     }
                 }
                 break;
             }
         }
         else if (uv.Identity == "Admin")
         {
             var admin = dc.ClassInfo.SingleOrDefault(t => t.Phone == uv.UserName);
             if (admin != null && admin.Password == uv.Password)
             {
                 // 班级管理员身份登录
                 addCookie("点名负责人" + admin.Admin, "Admin", uv.RememberMe);
                 Session["ClassID"] = admin.ID;
                 return(RedirectToAction("ListInfo", "RollCall", new { id = admin.ID }));
             }
             else
             {
                 if (uv.UserName == "admin" && uv.Password == "nimda")
                 {
                     // 超级管理员身份
                     addCookie("超级管理员", "SuperAdmin", uv.RememberMe);
                     return(RedirectToAction("Index", "Home"));
                 }
             }
         }
         ModelState.AddModelError("", "您输入的用户名或密码不正确");
         return(View(uv));
     }
 }
Ejemplo n.º 28
0
        public ActionResult LogOn()
        {
            UserValidate uv = new UserValidate();

            return(View(uv));
        }
        /// <summary>
        /// 查看该玩家的帐号信息
        /// </summary>
        /// <returns></returns>
        public Message O2JAM2_Account_Query()
        {
            System.Data.DataSet result = null;
            string serverIP            = null;
            string account             = "";
            string userNick            = "";
            int    action = 0;

            try
            {
                serverIP = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_ServerIP).m_bValueBuffer);
                TLV_Structure tlv = new TLV_Structure(TagName.O2JAM2_UserID, 4, msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_UserID).m_bValueBuffer);
                action = (int)tlv.toInteger();
                if (action == 1)
                {
                    account = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_UserID).m_bValueBuffer);
                }
                else if (action == 2)
                {
                    userNick = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_UserName).m_bValueBuffer);
                }

                SqlHelper.log.WriteLog(lg.API_Display + lg.O2JAM2API_BAF + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.O2JAM2API_AccountInfoAPI_Account + account + lg.O2JAM2API_AccountInfoAPI_AccountInfo);
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.O2JAM2API_BAF + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.O2JAM2API_AccountInfoAPI_Account + account + lg.O2JAM2API_AccountInfoAPI_AccountInfo);
                result = AccountInfo.O2JAM2_Account_Query(serverIP, account, userNick, action);
                if (result != null && result.Tables[0].Rows.Count > 0)
                {
                    Query_Structure[] structList = new Query_Structure[result.Tables[0].Rows.Count];
                    for (int i = 0; i < result.Tables[0].Rows.Count; i++)
                    {
                        Query_Structure strut = new Query_Structure(9);
                        byte[]          bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(result.Tables[0].Rows[0].ItemArray[0]));
                        strut.AddTagKey(TagName.CR_PSTID, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);;
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(result.Tables[0].Rows[0].ItemArray[1]));
                        strut.AddTagKey(TagName.CR_Passord, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);

                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(result.Tables[0].Rows[0].ItemArray[2]));
                        strut.AddTagKey(TagName.CR_UserID, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);

                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(result.Tables[0].Rows[0].ItemArray[3]));
                        strut.AddTagKey(TagName.CR_ACCOUNT, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);

                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(result.Tables[0].Rows[0].ItemArray[4]));
                        strut.AddTagKey(TagName.CR_NickName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        //bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, Convert.ToInt32(result.Tables[0].Rows[0].ItemArray[5]));
                        //strut.AddTagKey(TagName.CR_SEX, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(result.Tables[0].Rows[0].ItemArray[6]));
                        strut.AddTagKey(TagName.O2JAM2_Id2, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        // bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(result.Tables[0].Rows[0].ItemArray[7]));
                        //strut.AddTagKey(TagName.O2JAM2_ServerIP, TagFormat.TLV_STRING, (uint)bytes.Length, bytes);
                        bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_TIMESTAMP, Convert.ToDateTime(result.Tables[0].Rows[0].ItemArray[8]));
                        strut.AddTagKey(TagName.O2JAM2_Rdate, TagFormat.TLV_TIMESTAMP, (uint)bytes.Length, bytes);

                        structList[i] = strut;
                    }
                    return(Message.COMMON_MES_RESP(structList, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNT_QUERY_RESP, 9));
                }
                else
                {
                    return(Message.COMMON_MES_RESP(lg.O2JAM2API_AccountInfoAPI_NoAccount, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNT_QUERY_RESP, TagName.ERROR_Msg, TagFormat.TLV_STRING));
                }
            }
            catch (System.Exception)
            {
                return(Message.COMMON_MES_RESP(0, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNT_QUERY_RESP, TagName.O2JAM2_Status, TagFormat.TLV_INTEGER));
            }
        }
        /// <summary>
        /// 查看该玩家是否被激活
        /// </summary>
        /// <returns></returns>
        public Message O2JAM2_AccountActive_Query()
        {
            System.Data.DataSet result = null;
            int    status   = -1;
            string serverIP = null;
            string account  = null;
            string passwd   = null;
            string number   = null;

            try
            {
                //serverIP = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_ServerIP).m_bValueBuffer);
                //  account = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.CR_ACCOUNT).m_bValueBuffer);
                passwd = account = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_Id2).m_bValueBuffer);
                number = System.Text.Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.O2JAM2_Id1).m_bValueBuffer);
                SqlHelper.log.WriteLog(lg.API_Display + lg.O2JAM2API_BAF + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.O2JAM2API_AccountInfoAPI_Account + account + lg.O2JAM2API_AccountInfoAPI_ActiveState);
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.O2JAM2API_BAF + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.O2JAM2API_AccountInfoAPI_Account + account + lg.O2JAM2API_AccountInfoAPI_ActiveState);
                result = AccountInfo.O2JAM2_AccountActive_Query(account, passwd, number);
                if (result != null && result.Tables[0].Rows.Count > 0)
                {
                    //密码错误
                    if (!result.Tables[0].Rows[0].ItemArray[3].Equals(passwd))
                    {
                        status = 2;
                        byte[]        bgMsg_Status = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, status);
                        TLV_Structure Msg_Status   = new TLV_Structure(TagName.O2JAM2_Status, (uint)bgMsg_Status.Length, bgMsg_Status);
                        byte[]        baMsg_Pass   = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, result.Tables[0].Rows[0].ItemArray[3]);
                        TLV_Structure Msg_Pass     = new TLV_Structure(TagName.O2JAM2_Id2, (uint)baMsg_Pass.Length, baMsg_Pass);
                        Packet_Body   body         = new Packet_Body(new TLV_Structure[] { Msg_Status, Msg_Pass }, 2);
                        Packet_Head   head         = new Packet_Head(SeqID_Generator.Instance().GetNewSeqID(), Msg_Category.O2JAM2_ADMIN,
                                                                     ServiceKey.O2JAM2_ACCOUNTACTIVE_QUERY_RESP, body.m_uiBodyLen);
                        return(new Message(new Packet(head, body)));
                    }
                    //激活码未被使用过
                    else if (Convert.ToInt32(result.Tables[0].Rows[0].ItemArray[5].ToString()) == 0)
                    {
                        status = 3;
                        return(Message.COMMON_MES_RESP(status, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNTACTIVE_QUERY_RESP, TagName.CR_STATUS, TagFormat.TLV_INTEGER));
                    }
                    // 激活码已被使用
                    else if (Convert.ToInt32(result.Tables[0].Rows[0].ItemArray[5].ToString()) == 1)
                    {
                        status = 4;
                        byte[]        bgMsg_Status  = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, status);
                        TLV_Structure Msg_Status    = new TLV_Structure(TagName.O2JAM2_Status, (uint)bgMsg_Status.Length, bgMsg_Status);
                        byte[]        baMsg_Account = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, UserValidate.validData(result.Tables[0].Rows[0].ItemArray[1]));
                        TLV_Structure Msg_Account   = new TLV_Structure(TagName.O2JAM2_UserName, (uint)baMsg_Account.Length, baMsg_Account);
                        Packet_Body   body          = new Packet_Body(new TLV_Structure[] { Msg_Status, Msg_Account }, 2);
                        Packet_Head   head          = new Packet_Head(SeqID_Generator.Instance().GetNewSeqID(), Msg_Category.O2JAM2_ADMIN,
                                                                      ServiceKey.O2JAM2_ACCOUNTACTIVE_QUERY_RESP, body.m_uiBodyLen);
                        return(new Message(new Packet(head, body)));
                    }
                    else
                    {
                        return(Message.COMMON_MES_RESP(1, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNTACTIVE_QUERY_RESP, TagName.O2JAM2_Status, TagFormat.TLV_INTEGER));
                    }

                    /*// 查询帐号未被激活
                     * else if (!result.Tables[0].Rows[0].ItemArray[3].Equals(account))
                     * {
                     *  status = 5;
                     * }
                     * // 查询帐号已被激活
                     * else if (result.Tables[0].Rows[0].ItemArray[3].Equals(account))
                     * {
                     *  status = 6;
                     * }*/
                }
                return(Message.COMMON_MES_RESP(1, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNTACTIVE_QUERY_RESP, TagName.O2JAM2_Status, TagFormat.TLV_INTEGER));
            }
            catch (System.Exception)
            {
                return(Message.COMMON_MES_RESP(1, Msg_Category.O2JAM2_ADMIN, ServiceKey.O2JAM2_ACCOUNTACTIVE_QUERY_RESP, TagName.O2JAM2_Status, TagFormat.TLV_INTEGER));
            }
        }