Exemple #1
0
        public async Task <ActionResult> Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await staffManager.FindAsync(model.Email, model.Password);

                var foundUserByEmail = await staffManager.FindByEmailAsync(model.Email);

                bool isUserExist = false;
                if (foundUserByEmail != null)
                {
                    isUserExist = await staffManager.CheckPasswordAsync(foundUserByEmail, model.Password);
                }
                if (user != null)
                {
                    return(await Authenticate(user));
                }
                else if (isUserExist)
                {
                    return(await Authenticate(foundUserByEmail));
                }
                else
                {
                    ModelState.AddModelError("", Constants_files.Constants.INVALIDA_LOGIN_DATA);
                }
            }
            ViewBag.returnUrl = returnUrl;
            return(View(model));
        }
        public async Task <JsonResult> Signin(string signinName, string password)
        {
            Staff staff = await StaffManager.FindStaffBySigninName(signinName);

            if (staff == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {signinName} No SigninName, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有此登录名")));
            }
            if (!await StaffManager.CheckPasswordAsync(staff, password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {signinName} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {password}");

                return(Json(new JsonError("密码不正确")));
            }

            Hotel hotel = await YummyOnlineManager.GetHotelById(staff.HotelId);

            if (!hotel.Usable)
            {
                return(Json(new JsonError("该饭店不可用,请联系管理员")));
            }
            CurrHotel = hotel;

            if (!await HotelManager.IsStaffHasSchema(staff.Id, HotelDAO.Models.Schema.ReadWaiterData))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {staff.Id} (HotelId {staff.HotelId}) No Authority, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有权限")));
            }
            SigninManager.Signin(staff, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"Staff Signin: {staff.Id} (HotelId {staff.HotelId}), Host: {Request.UserHostAddress}");

            return(Json(new JsonSuccess {
                Data = staff.Id
            }));
        }