Exemplo n.º 1
0
        public async Task <IActionResult> AddOrUpdate(UserAccountEntry userAccountEntry)
        {
            ViewData["DataType"] = typeof(UserAccountEntry);
            await userAccountBusiness.AddOrUpdateUser(userAccountEntry, UserAccountBusiness.GeneralUserRoleKey);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update password of user account
        /// </summary>
        /// <param name="userAccount">object which contains new password</param>
        void IDataConnection.UpdateUserAccountPassword(UserAccountEntry userAccount)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.ConnectionString(CONNECTION_STRING)))
            {
                var p = new DynamicParameters();
                p.Add("@EmployeeId", userAccount.EmployeeId);
                p.Add("@PasswordSalt", userAccount.PasswordSalt);
                p.Add("@PasswordHash", userAccount.PasswordHash);


                connection.Execute("dbo.spUserAccount_UpdatePassword", p, commandType: CommandType.StoredProcedure);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates new employee and new user account with email and password
        /// </summary>
        /// <param name="employee">Object of an Employee</param>
        /// <param name="userCredentials">Object of an User Account</param>
        /// <returns>Created Employee</returns>
        public void CreateEmployeeUserAccount(Employee employee, UserAccountEntry userCredentials)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.ConnectionString(CONNECTION_STRING)))
            {
                // IDbTransaction transaction = connection.BeginTransaction();


                // ----------- Get Department Id -----------

                var p = new DynamicParameters();
                p.Add("@name", employee.Department.ToString());
                int departmentId = 0;

                List <int> tmp_ids = connection.Query <int>("dbo.spDepartment_GetDepartmentId", p, commandType: CommandType.StoredProcedure).ToList();

                foreach (var id in tmp_ids)
                {
                    departmentId = id;
                    break;
                }


                // ----------- Create Employee -----------
                p = new DynamicParameters();


                p.Add("@FirstName", employee.FirstName);
                p.Add("@LastName", employee.LastName);
                p.Add("@Department", departmentId);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spEmployee_Insert", p, commandType: CommandType.StoredProcedure);

                employee.Id = p.Get <int>("@id");


                // ----------- Create User Account -----------
                p = new DynamicParameters();


                p.Add("@EmployeeId", employee.Id);
                p.Add("@PasswordHash", userCredentials.PasswordHash);
                p.Add("@PasswordSalt", userCredentials.PasswordSalt);
                p.Add("@EmailAddress", userCredentials.EmailAddress);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);


                connection.Execute("dbo.spUserAccount_Insert", p, commandType: CommandType.StoredProcedure);
            }
        }
        private UserAccountEntry GetSampleUserAccount(string emailAddress)
        {
            if (!emailAddress.Equals(""))
            {
                UserAccountEntry userAccount = new UserAccountEntry("*****@*****.**", "password");
                userAccount.Id         = 1;
                userAccount.EmployeeId = 1;

                return(userAccount);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public static UserAccountEntry GetOrSetUser(string userName, string avatar)
        {
            var dbcontext = GetDbContext();
            var userModel = dbcontext.Set <UserAccountEntry>().FirstOrDefault(x => x.NickName == userName);

            if (userModel == null)
            {
                userModel = new UserAccountEntry
                {
                    Id       = Guid.NewGuid(),
                    NickName = userName,
                    Avatar   = avatar,
                };
                dbcontext.Set <UserAccountEntry>().Add(userModel);
                dbcontext.SaveChanges();
            }
            return(userModel);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 微信网页登录
        /// 兼容服务端渲染与前端渲染页面
        /// </summary>
        /// <returns>用户Id</returns>
        public async Task <string> WxWebLoin(WebAppAuthUserInfo userInfo)
        {
            var targetUserAccount = await userAccountAccessor.OneAsync <UserAccountEntry>(x => x.WeChat.OpenIdMapping
                                                                                          .Any(c => c.Source == userInfo.AppId && c.OpenId == userInfo.OpenId));

            if (targetUserAccount == null)
            {
                targetUserAccount = new UserAccountEntry
                {
                    WeChat = new UserAccountWeChat
                    {
                        OpenIdMapping = new List <WeChatAccountOpenIdMapping> {
                            new WeChatAccountOpenIdMapping
                            {
                                Source  = userInfo.AppId,
                                OpenId  = userInfo.OpenId,
                                Type    = userInfo.WxLoginType,
                                UnionId = userInfo.UnionId,
                                Id      = Guid.NewGuid()
                            }
                        },
                        Id      = Guid.NewGuid(),
                        UnionId = userInfo.UnionId
                    },
                    Id         = Guid.NewGuid(),
                    CreateTime = DateTime.Now
                };
                await userAccountAccessor.Add(targetUserAccount);
            }

            targetUserAccount.Avatar   = userInfo.HeadImgUrl;
            targetUserAccount.NickName = userInfo.NickName;
            if (targetUserAccount.Profile == null)
            {
                targetUserAccount.Profile = new UserAccountProfile();
            }
            targetUserAccount.Profile.Location = userInfo.Country + "," + userInfo.Country + "," + userInfo.Province;
            await userAccountAccessor.Update(targetUserAccount);

            return(targetUserAccount.Id.ToString());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns User Credentials such as passwordHash, passwordSalt and employee id of db entry
        /// </summary>
        /// <param name="emailAddress">Email Address of user that logs in</param>
        /// <returns></returns>
        public UserAccountEntry GetUserAccountCredentials(string emailAddress)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.ConnectionString(CONNECTION_STRING)))
            {
                UserAccountEntry userCredentials = new UserAccountEntry();

                var p = new DynamicParameters();
                p.Add("@EmailAddress", emailAddress);

                List <UserAccountEntry> tmp_userAccount = connection.Query <UserAccountEntry>("dbo.spUserAccount_GetUserCredentials", p, commandType: CommandType.StoredProcedure).ToList();

                if (tmp_userAccount.Count == 0)
                {
                    throw new TrainingPlatformException("No user account found with given email address and password.");
                }

                userCredentials = tmp_userAccount.First();

                return(userCredentials);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="registerModel"></param>
        /// <returns>注册结果(bool) , 注册信息, 用户ID(string)</returns>
        public async Task <Tuple <bool, string, string> > RegisterUserAdminNamePwd(CaRegisterModel registerModel)
        {
            if (registerModel == null)
            {
                return(Tuple.Create(false, "注册信息为空", string.Empty));
            }

            if (string.IsNullOrEmpty(registerModel.UserName) || string.IsNullOrEmpty(registerModel.Password))
            {
                return(Tuple.Create(false, "用户名或密码不能为空", string.Empty));
            }

            var userEntity = await userAccountAccessor.OneAsync <UserAccountUserNamePwd>(x => x.UserName == registerModel.UserName);

            if (userEntity != null)
            {
                return(Tuple.Create(false, "用户名已经存在", string.Empty));
            }

            string sha256String = EncryptPwd(registerModel.Password);

            var userAccountEntry = new UserAccountEntry
            {
                Id          = Guid.NewGuid(),
                NickName    = string.IsNullOrEmpty(registerModel.NickName) ? registerModel.NickName : RandomName(),
                Avatar      = RandomAvatar(),
                UserNamePwd = new UserAccountUserNamePwd
                {
                    Id         = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    Password   = sha256String,
                    UserName   = registerModel.UserName
                },
                InviteOrigin = new UserAccountInviteOrign
                {
                    Id        = Guid.NewGuid(),
                    InviteKey = registerModel.InviteOrigin
                },
                Phone = new UserAccountPhone
                {
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid(),
                    Phone      = registerModel.Mobile
                },
                Roles = new List <UserAccountBusinessRole>
                {
                    new UserAccountBusinessRole {
                        Id         = Guid.NewGuid(),
                        CreateTime = DateTime.Now,
                        RoleName   = AdminUserRoleKey
                    }
                },
                CreateTime = DateTime.Now
            };

            try
            {
                await userAccountAccessor.Add(userAccountEntry);
            }
            catch (Exception exc)
            {
                return(Tuple.Create(false, "异常: " + exc.Message, string.Empty));
            }
            return(Tuple.Create(true, "注册成功", userAccountEntry.Id.ToString()));
        }
Exemplo n.º 9
0
 public async Task AddOrUpdateUser(UserAccountEntry userAccountEntry, string roleName)
 {
     await userAccountAccessor.AddOrUpdate(userAccountEntry);
 }
Exemplo n.º 10
0
        private async Task SetSohuNewsDetail(SpiderLog spiderLog, IWebDriver webDriver)
        {
            var dbCtx = GetDbContext();

            var authElement    = webDriver.FindElement(By.CssSelector(".column.left"));
            var articleElement = webDriver.FindElement(By.CssSelector(".left.main"));


            var auth_img  = authElement.FindValueByCss(".user-pic img@src");
            var auth_name = authElement.FindValueByCss(".user-info h4@text");

            var article_title      = articleElement.FindValueByCss(".text-title h1@text");
            var article_createTime = articleElement.FindValueByCss(".text-title .article-info .time@text");
            var article_tags       = articleElement.FindMultiValueByCss(".text-title .article-info .tag@text");
            var article_content    = articleElement.FindValueByCss(".article@html");
            var article_imgs       = articleElement.FindMultiValueByCss(".article img@src");

            var excitedAccount = await dbCtx.Set <UserAccountEntry>().FirstOrDefaultAsync(x => x.NickName == auth_name);

            if (excitedAccount == null)
            {
                excitedAccount = new UserAccountEntry()
                {
                    Id       = Guid.NewGuid(),
                    Avatar   = auth_img,
                    NickName = auth_name
                };
                await dbCtx.AddAsync(excitedAccount);

                await dbCtx.SaveChangesAsync();
            }

            var excitedArticle = await dbCtx.ContentEntry.FirstOrDefaultAsync(x => x.Title == article_title);

            if (excitedArticle == null)
            {
                var imgList = new List <FileEntry>();
                if (article_imgs != null && article_imgs.Count > 0)
                {
                    foreach (var item in article_imgs)
                    {
                        imgList.Add(new FileEntry
                        {
                            ActualPath = item,
                            CreateTime = DateTime.Now,
                            Name       = "tmppath",
                            Id         = Guid.NewGuid()
                        });
                    }
                }
                var tagList = new List <Tags>();
                if (article_tags != null && article_tags.Count > 0)
                {
                    foreach (var item in article_tags)
                    {
                        tagList.Add(new Tags
                        {
                            Id   = Guid.NewGuid(),
                            Name = item
                        });
                    }
                }
                var articleId = Guid.NewGuid();
                var category  = await dbCtx.Categories.FirstOrDefaultAsync(x => x.Name == "资讯");

                var article = new ContentEntry
                {
                    Category         = category,
                    Id               = articleId,
                    Content          = article_content,
                    CreateTime       = DateTime.Parse(article_createTime),
                    MediaResource    = imgList,
                    Title            = article_title,
                    Tags             = tagList,
                    ContentEntryInfo = new ContentEntryInfo
                    {
                        Author        = auth_name,
                        Source        = spiderLog.TargetUrl,
                        Id            = articleId,
                        Type          = "资讯",
                        UserAccount   = excitedAccount,
                        UserAccountId = excitedAccount.Id
                    }
                };
                await dbCtx.AddAsync(article);

                await dbCtx.SaveChangesAsync();
            }
        }