예제 #1
0
        public void Add(string os, string browser)
        {
            var newInfo = new SignInInfo(os, browser);
            var insert  = TableOperation.Insert(newInfo);

            table.Execute(insert);
        }
예제 #2
0
        public async Task <ActionResult> DoAsync(SignInInfo model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.InvalidModelState(this.ModelState));
            }

            try
            {
                bool isValid = await this.CheckPasswordAsync(model.Email, model.Password).ConfigureAwait(false);

                if (!isValid)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }

                var result = await DAL.SignIn.DoAsync(this.Tenant, model.Email, model.OfficeId, this.RemoteUser.Browser, this.RemoteUser.IpAddress, model.Culture.Or("en-US")).ConfigureAwait(false);

                return(await this.OnAuthenticatedAsync(result, model).ConfigureAwait(true));
            }
            catch (DbException ex)
            {
                Log.Information(ex.Message);
                return(this.AccessDenied());
            }
        }
예제 #3
0
        public ActionResult Do(SignInInfo model)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            try
            {
                bool isValid = this.CheckPassword(model.Email, model.Password);

                if (!isValid)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }

                var result = DAL.SignIn.Do(model.Email, model.OfficeId, this.RemoteUser.Browser,
                                           this.RemoteUser.IpAddress, model.Culture.Or("en-US"));
                return(this.OnAuthenticated(result, model));
            }
            catch (NpgsqlException)
            {
                return(this.AccessDenied());
            }
        }
예제 #4
0
        public void OnResetItemHandler(GameObject go, int index)
        {
            SignInButton btn  = go.GetComponent <SignInButton>();
            SignInInfo   info = SignInProxy.instance.SignInList[index];

            btn.Set(info);
        }
        protected async Task <ActionResult> OnAuthenticatedAsync(LoginResult result, SignInInfo model = null)
        {
            if (!result.Status)
            {
                int delay = new Random().Next(1, 5) * 1000;

                await Task.Delay(delay).ConfigureAwait(false);

                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, JsonConvert.SerializeObject(result)));
            }


            Guid?applicationId = null;

            if (model != null)
            {
                applicationId = model.ApplicationId;
            }

            var loginView = await AppUsers.GetCurrentAsync(this.Tenant, result.LoginId).ConfigureAwait(false);

            var manager = new Provider(this.Tenant, applicationId, result.LoginId, loginView.UserId, loginView.OfficeId);
            var token   = manager.GetToken();

            await AccessTokens.SaveAsync(this.Tenant, token, this.RemoteUser.IpAddress, this.RemoteUser.UserAgent).ConfigureAwait(true);

            string domain = TenantConvention.GetDomain();

            this.AddAuthenticationCookie(domain, token);
            this.AddCultureCookie(domain, model?.Culture.Or("en-US"));

            return(this.Ok(token.ClientToken));
        }
예제 #6
0
        /// <summary>
        /// 进行初始化,加载TemplatePath页面,JavaScript脚本,进行用户SignInInfo状态判断
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (this.DesignMode == false)
            {
                ISignInUserInfo signInUserInfo = OnInitSignInControl();

                if (signInUserInfo != null)
                {
                    ITicket ticket = Ticket.Create(SignInInfo.Create(signInUserInfo,
                                                                     (bool)PassportWebControlHelper.GetControlValue(this.TemplateControl, "dontSaveUserName", "Checked", false),
                                                                     (bool)PassportWebControlHelper.GetControlValue(this.TemplateControl, "autoSignIn", "Checked", false)),
                                                   HttpContext.Current.Request.QueryString["ip"]);

                    RedirectToAppUrl(ticket);
                }
                else
                {
                    if (TemplatePath != string.Empty)
                    {
                        this.templateControl = Page.LoadControl(TemplatePath);

                        this.Controls.Add(this.templateControl);

                        InitScript();
                        Initialize();
                    }
                }
            }
        }
예제 #7
0
        private void RefreshSignByProtocol(int signId)
        {
            scrollContent.RefreshAllContentItems();
            Refresh();
            List <SignInInfo> signList = SignInProxy.instance.SignInList;
            SignInInfo        info     = null;

            for (int i = 0, count = signList.Count; i < count; i++)
            {
                info = signList[i];
                if (info.id == signId)
                {
                    List <GameResData> dataList = new List <GameResData>();
                    dataList.AddRange(info.signData.awardItemList);
                    if (VIPProxy.instance.VIPLevel >= info.signData.vip_lv)
                    {
                        for (int j = 1, count2 = info.signData.vip_multiple; j < count2; j++)
                        {
                            dataList.AddRange(info.signData.awardItemList);
                        }
                    }
                    //Logic.UI.Pvp.View.PvpGainRewardView.Open(dataList,true);
                    //Logic.UI.Tips.View.CommonRewardAutoDestroyTipsView.Open(dataList,true);
                    LuaCsTransfer.OpenRewardTipsView(UIUtil.CombineGameResList(dataList));
                    break;
                }
            }
        }
예제 #8
0
        public ActionResult Do(SignInInfo model)
        {
            System.Threading.Thread.Sleep(1000);

            string challenge = Session["Challenge"].ToString();

            if (model.Challenge != challenge)
            {
                return(Redirect("/"));
            }

            model.Browser   = this.RemoteUser.Browser;
            model.IpAddress = this.RemoteUser.IpAddress;

            try
            {
                LoginResult result = DAL.SignIn.Do(model.Email, model.OfficeId, model.Challenge, model.Password,
                                                   model.Browser, model.IpAddress, model.Culture);
                return(this.OnAuthenticated(result));
            }
            catch (NpgsqlException)
            {
                return(Json("Access is denied."));
            }
        }
예제 #9
0
        public async Task <IActionResult> SigIn([FromBody] SignInInfo signInData)
        {
            IActionResult response = StatusCode((int)HttpStatusCode.Forbidden);

            var email    = signInData.Email;
            var password = signInData.Password;

            if (!string.IsNullOrWhiteSpace(email) && !string.IsNullOrWhiteSpace(password))
            {
                email = email.ToLower();

                try
                {
                    var user = await
                               _database.User.SingleOrDefaultAsync(u => u.Email == email);

                    if (user == null)
                    {
                        _logger.LogDebug($"User sign in - invalid email: {email}");
                    }
                    else
                    {
                        var passwordHash = GetPasswordHash(password);

                        if ((user.IsLocked != true) && (user.Password == passwordHash))
                        {
                            await SignInUser(user);
                            await LoadUserRelationships(user);

                            user.LoginAttempts = 0;
                            response           = Ok(user);
                        }
                        else if (user.IsLocked != true)
                        {
                            user.LoginAttempts = user.LoginAttempts ?? 0;
                            if (user.LoginAttempts + 1 < _appSettings.MaxSignInAttempts)
                            {
                                user.LoginAttempts++;
                            }
                            else
                            {
                                user.LoginAttempts++;
                                user.IsLocked = true;
                                response      = StatusCode(423); // 423 Locked
                            }
                        }

                        await UpdateUser(user);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogDebug(null, ex, "Unexpected Issue.");
                    response = StatusCode((int)HttpStatusCode.InternalServerError);
                }
            }

            return(response);
        }
예제 #10
0
        private static string PrepareTicket()
        {
            ISignInInfo signInInfo = SignInInfo.Create("SinoOceanLand\\liumh");

            ITicket ticket = Ticket.Create(signInInfo);

            return(ticket.ToEncryptString());
        }
예제 #11
0
        public bool ConfirmPass(SignInInfo info)
        {
            var user = GetByLogin(info.Login);

            if (user != null)
            {
                return(Crypto.VerifyHashedPassword(user.Password, info.Password));
            }
            return(false);
        }
        public void EnqueueAccount(ISession session, int accountID, string hwHash)
        {
            var info = new SignInInfo(session, accountID, hwHash);

            lock (_queueSync)
            {
                _signInInfos.Enqueue(info);
                SendQueueInfoToWaitingClients();
            }
        }
예제 #13
0
        public IActionResult Authenticate([FromBody] SignInInfo signIn)
        {
            var user = _usersQueries.Authenticate(signIn.UserName, signIn.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(user));
        }
예제 #14
0
 public IActionResult SignIn([FromBody] SignInInfo info)
 {
     if (_userManager.ConfirmPass(info))
     {
         if (_userManager.GetByLogin(info.Login).InActive)
         {
             var user = _userManager.GetByLogin(info.Login);
             return(StatusCode(StatusCodes.Status200OK, user));
         }
         return(StatusCode(StatusCodes.Status423Locked, "Account is not active"));
     }
     return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid login or password"));
 }
        public async Task <IActionResult> SignIn(SignInInfo model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await signInManager.EmailAndPasswordSignInAsync(model.Email, model.Password, false);

                    if (result.Succeeded)
                    {
                        var foundUser = await userManager.FindByEmailAsync(model.Email);

                        if (foundUser != null)
                        {
                            var retrunUser = new
                            {
                                foundUser.Id,
                                foundUser.Username,
                                foundUser.DisplayName,
                                foundUser.Photo,
                                foundUser.Email,
                            };
                            return(Accepted(retrunUser));
                        }
                    }

                    //return StatusCode(HttpStatusCode.Unauthorized);

                    return(StatusCode(HttpStatusCode.NotFound, new
                    {
                        Error = "Incorrect signin payload",
                        Description = "Please check your account information."
                    }));
                }


                //return StatusCode(HttpStatusCode.BadRequest, "Invalid payloads");
                return(InvalidModelResult());
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);

                return(ErrorResult(ex));
            }
        }
예제 #16
0
        /// <summary>
        /// 判断SignInInfo状态,如果在SignInInfo合法情况下,基于Session的Cookie,或者用户选择自动登录的进行自动登录。
        /// </summary>
        private void Initialize()
        {
            Control signInBtn = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "SignInButton");

            if (signInBtn != null && signInBtn is IButtonControl)
            {
                ((IButtonControl)signInBtn).Click += new EventHandler(SignInButton_Click);
            }

            if (Page.IsPostBack == false)
            {
                //从Cookie中得到登录信息
                ISignInInfo signInInfo = SignInInfo.LoadFromCookie();

                if (signInInfo != null)
                {
                    Trace.WriteLine(string.Format("认证服务,从cookie中得到用户{0}的认证信息", signInInfo.UserID), "PassportSDK");
                }

                this._PageData.LoadFromCookie();

                PassportSignInSettings settings = PassportSignInSettings.GetConfig();

                if (IsSignInInfoInvalid(signInInfo) == false)   //SignIn Info非法
                {
                    if (settings.IsSessionBased || this.PageData.AutoSignIn)
                    {
                        if (IsSelfAuthenticate == false)
                        {
                            AutoSignIn(signInInfo);     //May be execute Response.End when redirect to app's url
                        }
                    }
                }

                if (Page.IsPostBack == false)
                {
                    InitForm(this.PageData);
                }

                Page.Response.Expires = 0;
            }
        }
        protected async Task <ActionResult> OnAuthenticatedAsync(LoginResult result, SignInInfo model = null)
        {
            if (!result.Status)
            {
                await Task.Delay(new Random().Next(1, 5) *1000).ConfigureAwait(false);

                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, JsonConvert.SerializeObject(result)));
            }

            Guid?applicationId = null;

            if (model != null)
            {
                applicationId = model.ApplicationId;
            }

            var loginView = await AppUsers.GetCurrentAsync(this.Tenant, result.LoginId).ConfigureAwait(false);

            var    manager = new Provider(this.Tenant, applicationId, result.LoginId, loginView.UserId, loginView.OfficeId);
            var    token   = manager.GetToken();
            string domain  = TenantConvention.GetDomain();

            await
            AccessTokens.SaveAsync(this.Tenant, token, this.RemoteUser.IpAddress, this.RemoteUser.UserAgent)
            .ConfigureAwait(true);

            var cookie = new HttpCookie("access_token")
            {
                Value    = token.ClientToken,
                HttpOnly = true,
                Expires  = token.ExpiresOn.DateTime
            };

            //localhost cookie is not supported by most browsers.
            if (domain.ToLower() != "localhost")
            {
                cookie.Domain = domain;
            }

            this.Response.Cookies.Add(cookie);
            return(this.Ok(token.ClientToken));
        }
예제 #18
0
        public Result SignUp([FromForm] SignInInfo signInInfo)
        {
            if (UserServices.CheckNickname(signInInfo.Nickname))
            {
                throw new UserException(UserException.Type.NickExists);
            }
            var user = Services.UserServices.SignUp(signInInfo.Nickname, signInInfo.Password);

            if (user == null)
            {
                throw new MySytemException();
            }
            else
            {
                SaveSignInStatus(user);
                return(new Result <User> {
                    IsSuccess = true, Data = user
                });
            }
        }
예제 #19
0
        private ITicket AuthenticateUser()
        {
            HttpRequest request = HttpContext.Current.Request;

            string strSignInName = (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "Text", string.Empty);
            string strPassword   = (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "password", "value", string.Empty);

            ISignInUserInfo userInfo = DefaultAuthenticate(strSignInName, strPassword);

            ISignInInfo signInInfo = SignInInfo.Create(userInfo,
                                                       (bool)PassportWebControlHelper.GetControlValue(this.TemplateControl, "dontSaveUserName", "Checked", false),
                                                       (bool)PassportWebControlHelper.GetControlValue(this.TemplateControl, "autoSignIn", "Checked", false));

            SignInContext signInContext = DoPostAuthenticateOP(signInInfo);

            ITicket ticket = Ticket.Create(signInInfo, request.QueryString["ip"]);

            SaveFormStatus(signInContext.PageData);

            return(ticket);
        }
        protected ActionResult OnAuthenticated(LoginResult result, SignInInfo model = null)
        {
            if (!result.Status)
            {
                Thread.Sleep(new Random().Next(1, 5) * 1000);
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, JsonConvert.SerializeObject(result)));
            }

            Guid?applicationId = null;

            if (model != null)
            {
                applicationId = model.ApplicationId;
            }

            var    manager = new Provider(AppUsers.GetCatalog(), applicationId, result.LoginId);
            var    token   = manager.GetToken();
            string domain  = DbConvention.GetDomain();

            AccessTokens.Save(token, this.RemoteUser.IpAddress, this.RemoteUser.UserAgent);

            var cookie = new HttpCookie("access_token")
            {
                Value    = token.ClientToken,
                HttpOnly = true,
                Secure   = true,
                Expires  = token.ExpiresOn
            };

            //localhost cookie is not supported by most browsers.
            if (domain.ToLower() != "localhost")
            {
                cookie.Domain = domain;
            }

            this.Response.Cookies.Add(cookie);
            return(Json(token.ClientToken));
        }
예제 #21
0
        public Result SignIn([FromForm] SignInInfo signInInfo)
        {
            var name = HttpContext.Session.GetString("UserName");

            if (name != null)
            {
                throw new UserException(UserException.Type.AlreadySignIn);
            }
            var user = UserServices.SignIn(signInInfo.Nickname, signInInfo.Password);

            if (user == null)
            {
                return(new Result {
                    IsSuccess = true, Message = "Nickname or password wrong"
                });
            }
            else
            {
                SaveSignInStatus(user);
                return(new Result <User> {
                    IsSuccess = true, Data = user
                });
            }
        }
예제 #22
0
 public void Set(SignInInfo info)
 {
     this.info = info;
     Refresh();
 }