Example #1
0
        //common lib

        /// <summary>
        /// return  1 : success
        /// return  0 : error ,
        /// return -1 : Name_log exist,
        /// return -2 : error - comfirm password ,
        /// return -3 : Email exist
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Insert(user_log entity, string comfirm_password = null)
        {
            try
            {
                if (!Check_Username(entity.name_log, 0))
                {
                    if (entity.password_log != comfirm_password)
                    {
                        return(-2);
                    }
                    else if (Check_Email(entity.email, 0))
                    {
                        return(-3);
                    }
                    else
                    {
                        entity.password_log = Encryptor.MD5Hash(entity.password_log);
                        entity.created_at   = DateTime.Now;
                        entity.modified_at  = DateTime.Now;
                        db.user_log.Add(entity);
                        db.SaveChanges();
                        return(1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
Example #2
0
        public ActionResult Edit(user_log user, string comfirm_password)
        {
            if (ModelState.IsValid)
            {
                var dao     = new user_log_dao();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                user.modified_by = session.username;

                var result = dao.Update(user, comfirm_password);
                if (result == 1)
                {
                    SetAlert(StaticResources.Resources.Pub_UpdateSucess, "success");
                    return(RedirectToAction("Index", "UserLog"));
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", StaticResources.Resources.ComfirmPasswordIncorrect);
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", StaticResources.Resources.EmailExists);
                }
                else
                {
                    ModelState.AddModelError("", StaticResources.Resources.UpdateUserLogFailed);
                }
            }
            SetListUserGroup(user.user_group_id);
            return(View());
        }
Example #3
0
 public long LogOutInfoEntry(long userId)
 {
     try
     {
         user_log userLog = new user_log
         {
             user_id     = userId,
             logout_date = DateTime.Now,
             ip_address  = "ip"
         };
         _entities.user_log.Add(userLog);
         _entities.SaveChanges();
         return(userLog.ulogo_id);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #4
0
        public long LoginInfoEntry(long userId, string LoginInfoEntry, string loginName)
        {
            try
            {
                //string strHostName = System.Net.Dns.GetHostName();//get the pc name


                //string externalIP = "";
                //externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
                //externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")).Matches(externalIP)[0].ToString();

                //string strHostName = "";
                //strHostName = System.Net.Dns.GetHostName();
                //IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
                //IPAddress[] addr = ipEntry.AddressList;
                //string IP = addr[addr.Length - 1].ToString();

                //if (request.Properties.ContainsKey["MS_HttpContext"])
                //{
                //    var ctx = request.Properties["MS_HttpContext"] as HttpContextWrapper;
                //    if (ctx != null)
                //    {
                //        var ip = ctx.Request.UserHostAddress;
                //        //do stuff with IP
                //    }
                //}

                user_log userLog = new user_log
                {
                    user_id    = userId,
                    login_date = DateTime.Now,
                    ip_address = LoginInfoEntry,
                    login_name = loginName
                };
                _entities.user_log.Add(userLog);
                _entities.SaveChanges();
                return(userLog.ulogo_id);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #5
0
 public ActionResult Login(UserModel model)
 {
     using (ANDONEntities entities = new ANDONEntities())
     {
         string   pwd  = Untils.MD5Encrypt(model.PWD);
         user_log user = entities.user_log.Where(t => t.UID == model.UID && t.PWD == pwd).FirstOrDefault();
         if (user != null)
         {
             user.LogInTime = DateTime.Now;
             entities.SaveChanges();
             Mapper.CreateMap <user_log, UserModel>();       // 配置
             model = Mapper.Map <user_log, UserModel>(user); // 使用AutoMapper自动映射
             SessionHelper.Add("adminInfo", model, 120);
             return(Json(true));
         }
         else
         {
             return(Json(false));
         }
     }
 }
Example #6
0
 /// <summary>
 /// return  1 : success
 /// return  0 : error ,
 /// return -1 : error - comfirm password ,
 /// return -2 : Email exist
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="comfirm_password"></param>
 /// <returns></returns>
 public int Update(user_log entity, string comfirm_password = null)
 {
     try
     {
         if (entity.password_log != comfirm_password)
         {
             return(-1);
         }
         else if (Check_Email(entity.email, entity.id))
         {
             return(-2);
         }
         else
         {
             //get info user by id
             var info = db.user_log.Find(entity.id);
             //update field
             if (!string.IsNullOrEmpty(entity.password_log))
             {
                 entity.password_log = Encryptor.MD5Hash(entity.password_log);
                 info.password_log   = entity.password_log;
             }
             info.name_person     = entity.name_person;
             info.address_current = entity.address_current;
             info.email           = entity.email;
             info.phone           = entity.phone;
             info.user_group_id   = entity.user_group_id;
             info.modified_by     = entity.modified_by;
             info.modified_at     = DateTime.Now;
             info.is_active       = entity.is_active;
             db.SaveChanges();
             return(1);
         }
     }
     catch (Exception)
     {
         return(0);
     }
 }