Exemplo n.º 1
0
        public ActionResult Logout()
        {
            var signin = new SigninManager(HttpContext);

            signin.SignOut();
            return(Redirect("/"));
        }
Exemplo n.º 2
0
 public async Task <JsonResult> IsAuthenticated()
 {
     if (!await SigninManager.IsAuthenticated())
     {
         return(Json(new JsonError()));
     }
     return(Json(new JsonSuccess(await getCustomerInfo())));
 }
Exemplo n.º 3
0
        public virtual async Task <JsonResult> Signup(SignupViewModel model)
        {
            if ((string)Session["SmsCode"] != model.Code)
            {
                return(Json(new JsonError("验证码不正确", "code")));
            }
            if (model.PhoneNumber == null)
            {
                return(Json(new JsonError("手机号不能为空")));
            }
            if (model.Password == null)
            {
                return(Json(new JsonError("密码不能为空")));
            }
            if (model.Password == model.PasswordAga)
            {
                return(Json(new JsonError("密码不一致")));
            }
            User user;
            bool succeeded;

            if (await SigninManager.IsAuthenticated())
            {
                user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                user.PhoneNumber  = model.PhoneNumber;
                user.UserName     = model.PhoneNumber;
                user.PasswordHash = UserManager.GetMd5(model.Password);
                succeeded         = await UserManager.UpdateAsync(user);

                await UserManager.RemoveFromRoleAsync(user.Id, Role.Nemo);

                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Update: {User.Identity.GetUserId()}");
            }
            else
            {
                user = new User {
                    PhoneNumber = model.PhoneNumber,
                    UserName    = model.PhoneNumber
                };
                succeeded = await UserManager.CreateAsync(user, model.Password);
            }

            if (!succeeded)
            {
                return(Json(new JsonError("注册失败")));
            }
            await UserManager.AddToRoleAsync(user.Id, Role.Customer);

            SigninManager.Signin(user, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"User Signup: {user.Id} ({user.PhoneNumber})");

            return(Json(new JsonSuccess()));
        }
Exemplo n.º 4
0
 void Awake()
 {
     siginResultText.text = "";
     pinMaxLength         = pinItems.Count;
     pin = new string[pinMaxLength];
     for (int i = 0; i < pin.Length; i++)
     {
         pin[i] = "";
     }
     if (Instance == null)
     {
         Instance = this;
     }
     showPinToggle.isOn = showPin;
     showPinToggle.onValueChanged.AddListener((value) => OnToggleShowPinChanged(value));
     ChangeShowPinToggleIcon();
 }
Exemplo n.º 5
0
        public ActionResult Postback(LoginDataModel loginData)
        {
            var security = new SecurityManager(serviceFactory);

            try
            {
                security.VerifyUserLogin(loginData.Username, loginData.Password);
                var signin = new SigninManager(HttpContext);
                signin.SignIn(loginData.Username);
            }
            catch (AuthorizationException)
            {
                ViewBag.Message = "Login failed";
                return(View("index"));
            }

            return(Redirect("/"));
        }
Exemplo n.º 6
0
        public virtual async Task <JsonResult> Signin(SigninViewModel model)
        {
            User user = await UserManager.FindByPhoneNumberAsync(model.PhoneNumber);

            if (user == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Signin: {model.PhoneNumber} No PhoneNumber, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("手机未注册")));
            }
            if (!await UserManager.CheckPasswordAsync(user, model.Password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Signin: {model.PhoneNumber} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {model.Password}");

                return(Json(new JsonError("密码不正确")));
            }
            if (User.Identity.IsAuthenticated)
            {
                User oldUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (oldUser != null && await UserManager.IsInRoleAsync(oldUser.Id, Role.Nemo))
                {
                    // 原来为匿名用户, 每个饭店该匿名用户点过的订单转移到登录的用户帐号下
                    List <Hotel> hotels = await YummyOnlineManager.GetHotels();

                    foreach (Hotel h in hotels)
                    {
                        HotelManager hotelManager = new HotelManager(h.ConnectionString);
                        await hotelManager.TransferDines(oldUser.Id, user.Id);
                    }
                    await UserManager.TransferUserPrice(user, oldUser);

                    await UserManager.DeleteAsync(oldUser);

                    await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Transfer: {oldUser.Id} -> {user.Id}");
                }
            }
            SigninManager.Signin(user, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"User Signin: {user.Id} ({user.PhoneNumber}), Host: {Request.UserHostAddress}");

            return(Json(new JsonSuccess()));
        }
Exemplo n.º 7
0
        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
            }));
        }
        public async Task <ApiResponse <UserInfo> > LoginAsync(Login login)
        {
            var result = await SigninManager.PasswordSignInAsync(login.Username, login.Password, false, false);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByNameAsync(login.Username);

                return(new ApiResponse <UserInfo>()
                {
                    Content = new UserInfo()
                    {
                        Username = user.UserName,
                        Email = user.Email,
                        NativeCulture = user.NativeCulture
                    }
                });  //set user
            }
            return(new ApiResponse <UserInfo>()
            {
                Errors = new[] { "Wrong login or password." }
            });
        }
Exemplo n.º 9
0
        public async Task <JsonResult> Signin(string userName, string password, bool rememberMe)
        {
            User user = null;

            if (userName.Contains('@'))
            {
                user = await UserManager.FindByEmailAsync(userName);
            }
            else
            {
                user = await UserManager.FindByPhoneNumberAsync(userName);
            }
            if (user == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Admin Signin: {userName} No UserName, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("未找到此用户")));
            }
            if (!await UserManager.CheckPasswordAsync(user, password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Admin Signin: {userName} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {password}");

                return(Json(new JsonError("密码不正确")));
            }
            if (!await UserManager.IsInRoleAsync(user.Id, Role.Admin))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Admin Signin: {userName} No Authority, Host: {Request.UserHostAddress}");

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

            return(Json(new JsonSuccess()));
        }
Exemplo n.º 10
0
 public virtual JsonResult Signout()
 {
     SigninManager.Signout();
     return(Json(new JsonSuccess()));
 }
Exemplo n.º 11
0
 public async Task LogoutAsync()
 {
     await SigninManager.SignOutAsync();
 }
Exemplo n.º 12
0
        public async Task <JsonResult> Pay(Cart cart)
        {
            CartAddition addition = new CartAddition();

            // 新建或获取用户Id
            User user = await createOrGetUser(User.Identity.GetUserId(), "OrderSystem");

            if (user == null)
            {
                return(Json(new JsonError("创建匿名用户失败")));
            }
            SigninManager.Signin(user, true);
            addition.UserId = user.Id;

            // 创建新订单
            FunctionResult result = await OrderManager.CreateDine(cart, addition);

            if (!result.Succeeded)
            {
                if (await UserManager.IsInRoleAsync(user.Id, Role.Nemo))
                {
                    await UserManager.DeleteAsync(user);

                    await YummyOnlineManager.RecordLog(YummyOnlineDAO.Models.Log.LogProgram.Identity, YummyOnlineDAO.Models.Log.LogLevel.Warning, $"Anonymous User Deleted {user.Id}, Via OrderSystem");
                }
                await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Error, $"{result.Detail}, Host:{Request.UserHostAddress}", HttpPost.GetPostData(Request));

                return(Json(new JsonError(result.Message)));
            }

            Dine dine = ((Dine)result.Data);

            await newDineInform(dine, "OrderSystem");

            PayKind payKind = await HotelManager.GetPayKindById(cart.PayKindId);

            string redirectUrl = $"{payKind.CompleteUrl}?Succeeded={true}&DineId={dine.Id}";

            if (payKind.Type == PayKindType.Online)
            {
                DinePaidDetail mainPaidDetail = await HotelManager.GetDineOnlinePaidDetail(dine.Id);

                // 如果实际需要支付的价格等于0则直接显示支付完成界面
                if (mainPaidDetail.Price == 0)
                {
                    await onlinePayCompleted(dine.Id, null);
                }
                else
                {
                    redirectUrl = await getOnlineRedirectUrl(dine.Id);
                }
            }
            else
            {
                HotelConfig config = await HotelManager.GetHotelConfig();

                if (config.IsPrintReciptAfterPayingOffline)
                {
                    await requestPrintDine(dine.Id, new List <PrintType> {
                        PrintType.Recipt
                    });
                }
            }

            return(Json(new JsonSuccess(redirectUrl)));
        }