Exemple #1
0
        public UserLoginResponse GetUserType(string username, string productType, string serverType)
        {
            UserLoginType userLoginType = new UserLoginType();

            _context = (MICAUMContext)DbManager.GetContext(productType, serverType);
            // _context = new MICAUMContext(DbManager.GetDbConnectionString(productType));
            var user = _context.AspNetUsers.SingleOrDefault(x => x.UserName == username);

            if (user != null)
            {
                userLoginType.IsFirstTimeLogin = user.FirstTimeLogin;
                userLoginType.Id = user.Id;
                var loginProvider = _context.AspNetUserTokens.Where(x => x.UserId == user.Id).FirstOrDefault();
                if (loginProvider != null)
                {
                    userLoginType.LoginProvider = loginProvider.LoginProvider;
                }
                else
                {
                    userLoginType.LoginProvider = "Form";
                }

                //userLoginType.Status = BusinessStatus.Ok;
                return(new UserLoginResponse {
                    Status = BusinessStatus.Ok, userLogin = userLoginType, Id = userLoginType.IsFirstTimeLogin.ToString(), ResponseMessage = $"UserName Exist"
                });
            }
            else
            {
                return(new UserLoginResponse {
                    Status = BusinessStatus.NotFound, ResponseMessage = $"UserName does not Exist"
                });
            }
        }
        private void SaveOrUpdateRegistration(UserLoginType loginType, IServiceBase resolver, IOAuthTokens authToken, Dictionary<string, string> authInfo)
        {
            ViewContext context = resolver.ResolveService<ViewContext>();
            CommandBus commandBus = resolver.ResolveService<CommandBus>();
            IEntityIdGenerator entityIdGenerator = resolver.ResolveService<IEntityIdGenerator>();

            Logger.Debug("Login type: {0}", loginType);

            UserDocument existingUser = context.Users
                                               .AsQueryable()
                                               .FirstOrDefault(user => user.ThirdPartyId == authToken.UserId &&
                                                                       user.LoginType == loginType);

            if (existingUser != null)
            {
                UpdateUserRegistration command = new UpdateUserRegistration()
                {
                    AggregateId = existingUser.Id,
                    FirstName = authInfo["first_name"],
                    LastName = authInfo["last_name"],
                    AccessToken = authToken.AccessToken,
                    PhotoSmallUri = authInfo["photo"],
                    PhotoBigUri = authInfo["photo_big"],
                };

                Logger.Info("Existing user: {0}", command.Dump());
                
                UserId = existingUser.Id;
                commandBus.Send(command, UserId);

            }
            else
            {
                RegisterUser command = new RegisterUser
                {
                    AggregateId = entityIdGenerator.Generate(),
                    FirstName = authInfo["first_name"],
                    LastName = authInfo["last_name"],
                    LoginType = loginType,
                    ThirdPartyId = authToken.UserId,
                    AccessToken = authToken.AccessToken,
                    PhotoSmallUri = authInfo["photo"],
                    PhotoBigUri = authInfo["photo_big"]
                };

                Logger.Info("New user: {0}", command.Dump());

                UserId = command.AggregateId;
                commandBus.Send(command, UserId);
            }

            ICacheClient cacheClient = resolver.ResolveService<ICacheClient>();
            UpdateSession(cacheClient);
        }
Exemple #3
0
 public ActionResult Edit(UserLoginType obj)
 {
     try
     {
         NSession.Update(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { errorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
Exemple #4
0
        /// <summary>
        /// 根据Id获取
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public UserLoginType GetById(int Id)
        {
            UserLoginType obj = NSession.Get <UserLoginType>(Id);

            if (obj == null)
            {
                throw new Exception("返回实体为空");
            }
            else
            {
                return(obj);
            }
        }
Exemple #5
0
 public JsonResult DeleteConfirmed(int id)
 {
     try
     {
         UserLoginType obj = GetById(id);
         NSession.Delete(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { errorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = "true" }));
 }
Exemple #6
0
        private void UserLogin()
        {
            string        ip  = GetClientIP();
            string        mac = GetMACByIP(ip);
            UserLoginType obj = new UserLoginType
            {
                UserCode = CurrentUser.Code,
                UserName = CurrentUser.Realname,
                IP       = ip,
                MAC      = mac,
                CreateOn = DateTime.Now
            };

            NSession.Save(obj);
            NSession.Flush();
        }
Exemple #7
0
        private void UserLogin()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("username", "password", "noActive", GetValidateCodeInputName(validateActionName));

            string username  = _Request.Get("username", Method.Post, string.Empty, false);
            string password  = _Request.Get("password", Method.Post, string.Empty, false);
            bool   autoLogin = !string.IsNullOrEmpty(_Request.Get("autologin", Method.Post));
            bool   invisible = _Request.Get("invisible", Method.Post) == "true";

            string ip = _Request.IpAddress;

            //如果全局UserLoginType为Username -或者- 后台设置全局UserLoginType为All且用户选择了账号登陆  则为true
            UserLoginType loginType       = _Request.Get <UserLoginType>("logintype", Method.Post, UserLoginType.Username);
            bool          isUsernameLogin = (LoginType == UserLoginType.Username || (LoginType == UserLoginType.All && loginType == UserLoginType.Username));

            ValidateCodeManager.CreateValidateCodeActionRecode(validateActionName);

            if (!CheckValidateCode(validateActionName, msgDisplay))
            {
                return;
            }

            using (ErrorScope es = new ErrorScope())
            {
                bool success;
                try
                {
                    success = UserBO.Instance.Login(username, password, ip, autoLogin, isUsernameLogin);
                }
                catch (Exception ex)
                {
                    msgDisplay.AddException(ex);
                    success = false;
                }

                if (success)
                {
#if !Passport
                    UpdateOnlineStatus(OnlineAction.OtherAction, 0, "");
                    OnlineUserPool.Instance.Update(My, invisible);
#endif
                    Response.Redirect(ReturnUrl, true);
                }
                else
                {
                    if (es.HasUnCatchedError)
                    {
                        es.CatchError <UserNotActivedError>(delegate(UserNotActivedError err)
                        {
                            Response.Redirect(err.ActiveUrl);
                        });
                        es.CatchError <EmailNotValidatedError>(delegate(EmailNotValidatedError err)
                        {
                            Response.Redirect(err.ValidateUrl);
                        });
                        es.CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                }
            }
        }
Exemple #8
0
        public ActionResult Edit(int id)
        {
            UserLoginType obj = GetById(id);

            return(View(obj));
        }
Exemple #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //关闭侧边栏
            if (_Request.IsClick("Default_Close_Sidebar"))
            {
                ProcessUpdateUserOption(true);
            }
            //开启侧边栏
            if (_Request.IsClick("Default_Open_Sidebar"))
            {
                ProcessUpdateUserOption(false);
            }

            //快速登录
            if (_Request.IsClick("btLogin"))
            {
                MessageDisplay msgDisplay = CreateMessageDisplay();

                using (ErrorScope es = new ErrorScope())
                {
                    if (CheckValidateCode("login", msgDisplay))
                    {
                        ValidateCodeManager.CreateValidateCodeActionRecode("login");
                        string username = _Request.Get("username", Method.Post, string.Empty, false);
                        string password = _Request.Get("password", Method.Post, string.Empty, false);

                        //如果全局UserLoginType为Username -或者- 后台设置全局UserLoginType为All且用户选择了账号登陆  则为true
                        UserLoginType loginType       = _Request.Get <UserLoginType>("logintype", Method.Post, UserLoginType.Username);
                        bool          isUsernameLogin = (LoginType == UserLoginType.Username || (LoginType == UserLoginType.All && loginType == UserLoginType.Username));

                        int  cookieTime = _Request.Get <int>("cookietime", Method.Post, 0);
                        bool success;

                        try
                        {
                            success = UserBO.Instance.Login(username, password, _Request.IpAddress, cookieTime > 0, isUsernameLogin);
                            if (success == false)
                            {
                                if (es.HasUnCatchedError)
                                {
                                    es.CatchError <UserNotActivedError>(delegate(UserNotActivedError err)
                                    {
                                        Response.Redirect(err.ActiveUrl);
                                    });
                                    es.CatchError <EmailNotValidatedError>(delegate(EmailNotValidatedError err)
                                    {
                                        Response.Redirect(err.ValidateUrl);
                                    });
                                    es.CatchError <ErrorInfo>(delegate(ErrorInfo error)
                                    {
                                        msgDisplay.AddError(error);
                                    });
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            msgDisplay.AddException(ex);
                            success = false;
                        }

                        if (success)
                        {
                            BbsRouter.JumpToCurrentUrl();
                        }
                    }
                }
            }
            else
            {
                UpdateOnlineStatus(OnlineAction.ViewIndexPage, 0, "");

                //OnlineManager.UpdateOnlineUser(MyUserID, 0, 0, My.OnlineStatus, OnlineAction.ViewIndexPage, Request, Response);

                AddNavigationItem("欢迎光临,现在是" + UserNow);
            }

            ForumCollection tempForums = new ForumCollection();

            foreach (Forum forum in ForumCatalogs)
            {
                WaitForFillSimpleUsers <Moderator>(forum.Moderators);
                foreach (Forum subForum in forum.SubForumsForList)
                {
                    WaitForFillSimpleUsers <Moderator>(subForum.Moderators);
                }
                tempForums.AddRange(forum.SubForumsForList);
            }

            ForumBO.Instance.SetForumsLastThread(tempForums);

            SubmitFillUsers();
        }