Exemplo n.º 1
0
        // 進行密碼確認方法
        public bool PasswordCheck(Usertest checkUser, string password)
        {
            // 判斷資料庫裡的密碼資料與傳入密碼資料Hash 後是否一樣
            bool result = checkUser.Password.Equals(HashPassword(password));

            return(result);
        }
Exemplo n.º 2
0
        public void Register(Usertest newUser)
        {
            DateTime today = DateTime.Today;
            int      age   = today.Year - newUser.Birth.Year;

            if (newUser.Birth > today.AddYears(-age))
            {
                age--;
            }
            Double BMI = newUser.Weight / ((newUser.Height / 100) * (newUser.Height / 100));

            //HashPassword
            newUser.Password = HashPassword(newUser.Password);
            newUser.Age      = age;
            if (newUser.Sex == "男生")
            {
                newUser.BMR     = newUser.Weight * 13.7 + newUser.Height * 5.0 - (6.8 * age) + 66;
                newUser.Bodyfat = (1.2 * BMI) + (0.23 * age) - 5.4 - (10.8 * 1);
            }
            else if (newUser.Sex == "女生")
            {
                newUser.BMR     = newUser.Weight * 9.6 + newUser.Height * 1.8 - (4.7 * age) + 655;
                newUser.Bodyfat = (1.2 * BMI) + (0.23 * age) - 5.4 - (10.8 * 0);
            }
            _repository.Create(newUser);
            _db.Save();
        }
Exemplo n.º 3
0
        public ActionResult Registertest(Register2View RegisterUser)
        {
            Usertest newUser = Mapper.Map <Usertest>(RegisterUser);

            _usertestservices.Register(newUser);
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 4
0
        public bool AccountCheck(string account)
        {
            //取得會員資料
            Usertest serch = Get(account);
            //判斷是否有會員
            bool result = (serch == null);

            return(result);
        }
Exemplo n.º 5
0
        // 取得會員的權限角色資料
        public string GetRole(string account)
        {
            // 宣告初始角色字串
            string role = "User";
            // 取得傳入帳號的會員資料
            Usertest loginUser = Get(account);

            // 判斷資料庫欄位,用以確認是否為Admin
            if (loginUser.IsAdmin)
            {
                role += ",Admin";
            }
            // 回傳最後結果
            return(role);
        }
Exemplo n.º 6
0
        public IActionResult Create(Usertest item)
        {
            if (item.Name == null || item.Username == null || item.Password == null || item.Email == null || item.Age == 0)
            {
                return(StatusCode(400));
                //return BadRequest();
                //return NoContent();
                //Responses
            }
            else
            {
                _context.Usertests.Add(item);
                _context.SaveChanges();

                return(CreatedAtRoute("GetUser", new { id = item.Id }, item));
            }
        }
Exemplo n.º 7
0
        public IActionResult Update(long id, Usertest item)
        {
            var todo = _context.Usertests.Find(id);

            if (todo == null)
            {
                return(NotFound());
            }

            todo.Name     = item.Name;
            todo.Username = item.Username;
            todo.Password = item.Password;
            todo.Age      = item.Age;

            _context.Usertests.Update(todo);
            _context.SaveChanges();
            return(NoContent());
        }
Exemplo n.º 8
0
        //#region 登入

        //public string Login(User loginUser)
        //{
        //    string roleData = GetRole(loginUser.Account);
        //    // 新增一個登入用Ticket
        //    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1
        //    , loginUser.Account // 使用者名稱
        //    , DateTime.Now // 起始時間
        //    , DateTime.Now.AddMinutes(30) // 到期時間,這裡設定為30 分鐘後
        //    , false // 設定是否以Cookie 存取
        //    , roleData // 使用者資料,這裡存入角色資料
        //    , FormsAuthentication.FormsCookiePath); // 設定儲存路徑,使用預設路徑
        //    // 將資料加密成字串傳回
        //    // 將資料存入Cookies 中
        //    return FormsAuthentication.Encrypt(ticket);
        //}
        //#endregion

        #region 登入確認

        public string LoginCheck(string account, string password)
        {
            // 取得傳入帳號的使用者資料
            Usertest loginUser = Get(account);

            // 判斷是否有此使用者
            if (loginUser != null)
            {
                // 進行帳號密碼確認
                if (PasswordCheck(loginUser, password))
                {
                    return("");
                }
                else
                {
                    return(" 密碼輸入錯誤");
                }
            }
            else
            {
                return(" 無此使用者帳號,請去註冊");
            }
        }
Exemplo n.º 9
0
 public void Update(Usertest nowUser)
 {
     _repository.Update(nowUser);
     _db.Save();
 }
Exemplo n.º 10
0
        public string GetNameByAccount(string account)
        {
            Usertest currentUser = Get(account);

            return(currentUser.Account);
        }
Exemplo n.º 11
0
 public void ChangePassword(Usertest nowUser, string newPassword)
 {
     nowUser.Password = HashPassword(newPassword);
     Update(nowUser);
 }