Beispiel #1
0
        /// <summary>
        /// 註冊使用者
        /// <para>回傳項目</para>
        /// <para>Item1(bool) 註冊結果</para>
        /// <para>Item2(List<stirng>) 錯誤代碼</para>
        /// <para>Item3(string) 相關訊息</para>
        /// <para>Item4(UserList) 使用者資訊</para>
        /// </summary>
        /// <param name="userAccount">使用者名稱</param>
        /// <param name="userPw1">使用者密碼</param>
        /// <param name="userPw2">使用者密碼</param>
        /// <param name="email">Email</param>
        /// <returns></returns>
        public Tuple <bool, List <string>, string, UserList> RegisterUser(string userAccount, string userPw1, string userPw2, string email)
        {
            bool          result    = false;
            List <string> errorList = GetFieldCheckError(userAccount, userPw1, userPw2, email);
            string        msg       = "註冊失敗";
            UserList      userList  = new UserList();

            if (!errorList.Any())
            {
                try
                {
                    userList = new UserList
                    {
                        CreateDate = DateTime.Now,
                        CreateIP   = PBTool.GetIP(),
                        UserEmail  = email,
                        UserName   = userAccount,
                        UserPW     = GetSaltPW(userPw1),
                        UserAccess = 1,
                        UserStatus = true
                    };
                    messageBoardEntities.UserList.Add(userList);
                    messageBoardEntities.SaveChanges();
                    DoUserLog(userList.UserID, "註冊成功");
                    msg    = "註冊成功,即將跳轉至登入頁";
                    result = true;
                }
                catch (Exception err)
                {
                    errorList.Add("發生錯誤");
                    LogTool.DoErrorLog($"{err.Message}\r\n{err.StackTrace}");
                }
            }
            return(Tuple.Create(result, errorList, msg, userList));
        }
Beispiel #2
0
        /// <summary>
        /// 儲存使用者 Log 檔
        /// </summary>
        /// <param name="userID">使用者 ID</param>
        /// <param name="userOperator">訊息</param>
        private void DoUserLog(int userID, string userOperator)
        {
            try
            {
                UserLog userLog = new UserLog
                {
                    UserID       = userID,
                    UserOperator = userOperator,
                    IP           = PBTool.GetIP(),
                    CreateDate   = DateTime.Now
                };

                messageBoardEntities.UserLog.Add(userLog);
                messageBoardEntities.SaveChanges();

                // ToDo 20180817 操作紀錄
                //var userJSON = JsonConvert.SerializeObject(userLog);
            }
            catch (Exception err)
            {
                LogTool.DoErrorLog($"#{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff")}:{err.Message}\r\n");
                throw;
            }
        }