コード例 #1
0
        internal static bool UpdateUser(CommonUser oldUser)
        {
            DatabaseEntities entities = new DatabaseEntities();
            User             user     = entities.Users.FirstOrDefault(p => p.UserId == oldUser.UserId);

            if (user == null)
            {
                return(false);
            }
            user.Role       = oldUser.Role;
            user.AssignedTo = oldUser.AssignedTo;
            if (!string.IsNullOrEmpty(oldUser.Password))
            {
                string newSalt = GenerateSalt();
                user.PasswordSalt = newSalt;
                user.Password     = EncodePassword(oldUser.Password + newSalt);
            }

            entities.Users.Attach(user);
            var entry = entities.Entry(user);

            entry.Property(e => e.Role).IsModified         = true;
            entry.Property(e => e.AssignedTo).IsModified   = true;
            entry.Property(e => e.Password).IsModified     = true;
            entry.Property(e => e.PasswordSalt).IsModified = true;
            entities.SaveChanges();
            return(true);
        }
コード例 #2
0
        public async Task <IActionResult> ForgetPassword(ForgetPassword model)
        {
            if (ModelState.IsValid)
            {
                CommonUser user = await _commonUserSvc.CheckUser(model.Email);

                if (user != null)
                {
                    string token       = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                    var    callbackUrl = Url.Action("ResetPassword", "User", new { code = token });

                    using (var tx = CommonContext.Database.BeginTransaction())
                    {
                        user.Token    = token;
                        user.TokenUtc = DateTime.UtcNow;
                        CommonContext.Users.Update(user);

                        await CommonContext.SaveChangesAsync();

                        tx.Commit();
                    }

                    _logger.Error($"Sending Email email:{model.Email} callback:{callbackUrl}");
                    bool result = await _mailSvc.SendPasswordResetEmail(model.Email, callbackUrl);

                    _logger.Error($"Email Sent:");
                }
                ViewBag.SucessMessage = "Please check your email for a link to reset your password";
                return(View());
            }

            return(View(model));
        }
コード例 #3
0
        private async Task SignInUser(CommonUser user, bool rememberMe)
        {
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Sid, user.Id.ToString()),
                new Claim(Common.Constants.Security.Email, user.Email)
            };

            if (!string.IsNullOrWhiteSpace(user.FirstName))
            {
                claims.Add(new Claim(Common.Constants.Security.FirstName, user.FirstName));
            }

            if (!string.IsNullOrWhiteSpace(user.LastName))
            {
                claims.Add(new Claim(Common.Constants.Security.LastName, user.LastName));
            }

            if (user.Permission == SystemPermissions.Administrator)
            {
                claims.Add(new Claim(ClaimTypes.Role, SystemPermissions.Administrator.ToString()));
            }

            var identity        = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
            var claimsPrincipal = new ClaimsPrincipal(identity);
            var authProperties  = new AuthenticationProperties {
                IsPersistent = rememberMe
            };

            await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, authProperties);
        }
コード例 #4
0
        public ActionResult MyTournament()
        {
            CommonUser commonUser = new CommonUser();

            commonUser.tournament = new Tournament();
            if (Session["UserId"] != null)
            {
                Int64 UserId = Convert.ToInt64(Session["UserId"]);
                commonUser.tournament = DAL.GetTournament(0, UserId);

                List <Team> lstPlayer = new List <Team>();
                lstPlayer = DAL.GetListofTournament_Team(commonUser.tournament.TournamentId);
                commonUser.tournament.team = lstPlayer;
                List <ScheduleInfo> lstshcedule = new List <ScheduleInfo>();
                commonUser.tournament.scheduleInfo = new ScheduleInfo();
                commonUser.tournament.scheduleInfo.TournamentId = commonUser.tournament.TournamentId;
                lstshcedule = DAL.GetScheduleInfo(commonUser.tournament.scheduleInfo.TournamentId);
                commonUser.tournament.lstScheduleInfo = lstshcedule;
            }
            else
            {
                return(RedirectToAction("Index", "User"));
            }
            return(View(commonUser));
        }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: zzuqqiu/birdeye
        public JsonResult Save(PersonInfo updateUser)
        {
            //string path = Server.MapPath("/Content/logo.gif");
            //string path1 = Server.MapPath("Content/logo.gif");
            CommonUser user = new CommonUser();

            Test(updateUser.ObHeadPortrait);
            user.UserName  = updateUser.UserName;
            user.Email     = updateUser.Email;
            user.Comment   = updateUser.Comment;
            user.AccountId = User.Identity.Name;

            UpdateUserStatus status = new UserManager().UpdateUser(user);

            switch (status)
            {
            case UpdateUserStatus.InvalidEmailFormat:
                return(Json(UpdateUserStatus.InvalidEmailFormat.ToString()));

            case UpdateUserStatus.MultipleUserName:
                return(Json(UpdateUserStatus.MultipleUserName.ToString()));

            case UpdateUserStatus.InvalidAccountId:
                return(Json(UpdateUserStatus.InvalidAccountId.ToString()));

            case UpdateUserStatus.ServerError:
                return(Json(UpdateUserStatus.ServerError.ToString()));
            }

            Session[ConstantHelper.CurrentUser] = user.UserName;
            return(Json(updateUser));
        }
コード例 #6
0
        //
        // GET: /Tournament/

        public ActionResult AddTournament()
        {
            CommonUser commonUser = new CommonUser();

            commonUser.tournament = new Tournament();
            if (Session["UserId"] != null)
            {
                Int64 UserId = Convert.ToInt64(Session["UserId"]);
                commonUser.tournament = DAL.GetTournament(0, UserId);
                string refURL = Request.UrlReferrer.AbsolutePath;
                if (refURL == "/UserProfile/MyTournament")
                {
                }
                else
                {
                    if (commonUser.tournament != null)
                    {
                        if (!string.IsNullOrEmpty(commonUser.tournament.TournamentName) && !string.IsNullOrEmpty(commonUser.tournament.MobileNumber))
                        {
                            return(RedirectToAction("MyTournament", "UserProfile"));
                        }
                    }
                }
            }
            else
            {
                return(RedirectToAction("Index", "User"));
            }
            return(View(commonUser));
        }
コード例 #7
0
        public static async Task <CommonUser> Login(string username, string password)
        {
            CommonUser          user = new CommonUser();
            HttpResponseMessage response;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(DataHolder.ServerAddress);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic");

                try
                {
                    response = await client.GetAsync("api/users/login/" + username + "/" + password);
                }
                catch (HttpRequestException ex)
                {
                    throw new Exception(ex.InnerException.Message);
                }

                if (response.IsSuccessStatusCode)
                {
                    user = await response.Content.ReadAsAsync <CommonUser>();
                }
            }

            return(user);
        }
コード例 #8
0
        public static async Task <bool> PostEditUser(CommonUser user)
        {
            bool success = false;
            HttpResponseMessage response;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(DataHolder.ServerAddress);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic");

                try
                {
                    response = await client.PostAsJsonAsync("api/users/edit", user);
                }
                catch (HttpRequestException ex)
                {
                    throw new Exception(ex.InnerException.Message);
                }

                if (response.IsSuccessStatusCode)
                {
                    success = await response.Content.ReadAsAsync <bool>();
                }
            }

            return(success);
        }
コード例 #9
0
        internal static CommonUser Login(string username, string password)
        {
            CommonUser       user     = new CommonUser();
            DatabaseEntities entities = new DatabaseEntities();
            User             dbUser   = entities.Users.FirstOrDefault(p => p.Username == username);

            if (dbUser == null)
            {
                return(null);
            }
            string encodedPassword = EncodePassword(password + dbUser.PasswordSalt);

            if (dbUser.Password == encodedPassword)
            {
                user.Password     = dbUser.Password;
                user.AssignedTo   = dbUser.AssignedTo;
                user.Role         = dbUser.Role;
                user.Username     = dbUser.Username;
                user.OwnerId      = dbUser.OwnerId;
                user.RegisteredAt = dbUser.RegisteredAt;
                user.UserId       = dbUser.UserId;
                user.Permissions  = dbUser.Permissions;


                return(user);
            }
            return(null);
        }
コード例 #10
0
        internal static bool CreateUser(CommonUser user)
        {
            DatabaseEntities entities = new DatabaseEntities();
            User             check    = entities.Users.FirstOrDefault(p => p.Username == user.Username);

            if (check != null)
            {
                return(false);
            }
            User   newUser = new User();
            string salt    = GenerateSalt();

            newUser.Username     = user.Username;
            newUser.OwnerId      = user.OwnerId;
            newUser.PasswordSalt = salt;
            newUser.Password     = EncodePassword(user.Password + salt);
            newUser.RegisteredAt = DateTime.UtcNow;
            newUser.AssignedTo   = user.AssignedTo;
            newUser.Role         = user.Role;
            newUser.UserId       = Guid.NewGuid();
            newUser.Permissions  = "";
            entities.Users.Add(newUser);
            entities.SaveChanges();
            return(true);
        }
コード例 #11
0
        public JsonResult Save(PersonInfo updateUser)
        {
            CommonUser user = new CommonUser();

            user.UserName  = updateUser.UserName;
            user.Email     = updateUser.Email;
            user.Comment   = updateUser.Comment;
            user.AccountId = User.Identity.Name;

            UpdateUserStatus status = new UserManager().UpdateUser(user);

            switch (status)
            {
            case UpdateUserStatus.InvalidEmailFormat:
                return(Json(UpdateUserStatus.InvalidEmailFormat.ToString()));

            case UpdateUserStatus.MultipleUserName:
                return(Json(UpdateUserStatus.MultipleUserName.ToString()));

            case UpdateUserStatus.InvalidAccountId:
                return(Json(UpdateUserStatus.InvalidAccountId.ToString()));

            case UpdateUserStatus.ServerError:
                return(Json(UpdateUserStatus.ServerError.ToString()));
            }

            Session[ConstantHelper.CurrentUser] = user.UserName;
            return(Json(updateUser));
        }
コード例 #12
0
ファイル: UserRepository.cs プロジェクト: zzuqqiu/birdeye
        internal CommonUser GetUser(string id)
        {
            XmlNode node = this.userDoc.SelectSingleNode(ConstantHelper.User);

            CommonUser user = null;

            foreach (XmlNode item in node.ChildNodes)
            {
                XmlElement xe = (XmlElement)item;
                if (xe.GetAttribute(ConstantHelper.AccountId).ToUpper() == id.ToUpper())
                {
                    user = new CommonUser
                    {
                        AccountId        = xe.GetAttribute(ConstantHelper.AccountId),
                        UserName         = xe.GetAttribute(ConstantHelper.UserName),
                        Email            = xe.GetAttribute(ConstantHelper.Email),
                        Comment          = xe.GetAttribute(ConstantHelper.Comment),
                        PasswordQuestion = xe.GetAttribute(ConstantHelper.PasswordQuestion),
                        PasswordAnswer   = xe.GetAttribute(ConstantHelper.PasswordAnswer),
                        HaveSetUserName  = Convert.ToBoolean(xe.GetAttribute(ConstantHelper.HaveSetUserName))
                    };
                }
            }

            GetHeadPortrait(id, user);

            return(user);
        }
コード例 #13
0
        public ActionResult Edit(Guid id)
        {
            CommonUser entity = CommonUserService.GetModel(id);
            var        model  = Mapper.Map <CommonUserDTO>(entity);

            return(View(model));
        }
コード例 #14
0
 public Exception GetReviewsByCommonUser(ref CommonUser commonUser)
 {
     using (OracleConnection oracleConnection = Connection.GetInstance().ConnectionDB())
     {
         OracleCommand oracleCommand = new OracleCommand();
         oracleCommand.Connection  = oracleConnection;
         oracleCommand.CommandText = "PACK_REVIEW.GET_REVIEW_BY_COMMON_USER";
         oracleCommand.CommandType = CommandType.StoredProcedure;
         oracleCommand.Parameters.Add("COMMON_USER_ID", OracleDbType.Long).Value = commonUser.CommonUserId;
         OracleDataReader oracleDataReader;
         Exception        exceptionToReturn = null;
         try
         {
             oracleConnection.Open();
             oracleDataReader = oracleCommand.ExecuteReader();
             while (oracleDataReader.Read())
             {
                 Review review = new Review();
                 review = Mapping(oracleDataReader);
                 commonUser.Review.Add(review);
             }
             return(exceptionToReturn);
         }
         catch (Exception exception)
         {
             exceptionToReturn = exception;
             return(exceptionToReturn);
         }
     }
 }
コード例 #15
0
        private void dgvUsers_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvUsers.SelectedRows.Count != 1)
            {
                btnEditUser.Enabled        = false;
                btnDeleteUser.Enabled      = false;
                btnSavePermissions.Enabled = false;
            }
            else
            {
                btnEditUser.Enabled        = true;
                btnDeleteUser.Enabled      = true;
                btnSavePermissions.Enabled = true;
            }
            Dictionary <string, bool> userPermission = JsonConvert.DeserializeObject <Dictionary <string, bool> >(DataHolder.UserPermissions);

            if (userPermission != null)
            {
                if (userPermission.ContainsKey(btnEditUser.Tag.ToString()))
                {
                    if (dgvUsers.SelectedRows.Count == 1)
                    {
                        btnEditUser.Enabled = userPermission[btnEditUser.Tag.ToString()];
                    }
                    else
                    {
                        btnEditUser.Enabled = false;
                    }
                }
                else
                {
                    btnEditUser.Enabled = false;
                }
                if (userPermission.ContainsKey(btnDeleteUser.Tag.ToString()))
                {
                    if (dgvUsers.SelectedRows.Count == 1)
                    {
                        btnDeleteUser.Enabled = userPermission[btnDeleteUser.Tag.ToString()];
                    }
                    else
                    {
                        btnDeleteUser.Enabled = false;
                    }
                }
                else
                {
                    btnDeleteUser.Enabled = false;
                }
            }

            CheckPermission();
            if (dgvUsers.SelectedRows.Count == 1 && dgvUsers.SelectedRows[0] != null)
            {
                CommonUser user = (CommonUser)dgvUsers.SelectedRows[0].DataBoundItem;
                if (user.UserId == DataHolder.CurrnetUserId)
                {
                    btnSavePermissions.Enabled = false;
                }
            }
        }
コード例 #16
0
        private async void btnSavePermissions_Click(object sender, EventArgs e)
        {
            if (dgvUsers.SelectedRows.Count == 1 && dgvUsers.SelectedRows[0] != null)
            {
                CommonUser selectedItem = (CommonUser)dgvUsers.SelectedRows[0].DataBoundItem;
                Dictionary <string, bool> newPermissions = new Dictionary <string, bool>();
                foreach (TreeNode node in allNodes)
                {
                    if (node.Tag == null)
                    {
                        continue;
                    }
                    newPermissions.Add(node.Tag.ToString(), node.Checked);
                }

                var  output  = Newtonsoft.Json.JsonConvert.SerializeObject(newPermissions);
                bool success = await SAUsers.PostUpdateUserPermissions(selectedItem.UserId, output);

                if (success)
                {
                    labelError.Text      = "success_error_settings";
                    labelError.ForeColor = Color.Green;
                    labelError.Visible   = true;
                    LoadData();
                }
                else
                {
                    labelError.Text      = "fail_error_settings";
                    labelError.ForeColor = Color.Red;
                    labelError.Visible   = true;
                }
            }
        }
コード例 #17
0
        public ActionResult AddTeam()
        {
            //var player = DAL.GetPlayerByTeam(1);
            //Business.Entity.CommonUser c = new CommonUser();
            //c.team = new Team();
            //c.team.player = player;
            //return View(c);
            CommonUser commonUser = new CommonUser();

            commonUser.team = new Team();
            if (Session["UserId"] != null)
            {
                Int64 UserId = Convert.ToInt64(Session["UserId"]);
                commonUser.team = DAL.GetTeam(0, UserId);
                string refURL = Request.UrlReferrer.AbsolutePath;
                if (refURL == "/UserProfile/MyTeam")
                {
                }
                else
                {
                    if (commonUser.team != null)
                    {
                        if (!string.IsNullOrEmpty(commonUser.team.TeamName) && !string.IsNullOrEmpty(commonUser.team.MobileNumber))
                        {
                            return(RedirectToAction("MyTeam", "UserProfile"));
                        }
                    }
                }
            }
            else
            {
                return(RedirectToAction("Index", "User"));
            }
            return(View(commonUser));
        }
コード例 #18
0
 public Exception Register(ref CommonUser commonUser)
 {
     using (OracleConnection oracleConnection = Connection.GetInstance().ConnectionDB())
     {
         OracleCommand oracleCommand = new OracleCommand();
         oracleCommand.Connection  = oracleConnection;
         oracleCommand.CommandText = "PACK_COMMON_USER.REGISTER_COMMON_USER";
         oracleCommand.CommandType = CommandType.StoredProcedure;
         oracleCommand.Parameters.Add("FIRST_NAME_PARAMETER", OracleDbType.Varchar2).Value     = commonUser.FirstName;
         oracleCommand.Parameters.Add("SECOND_NAME_PARAMETER", OracleDbType.Varchar2).Value    = commonUser.SecondName;
         oracleCommand.Parameters.Add("FIRST_SURNAME_PARAMETER", OracleDbType.Varchar2).Value  = commonUser.FirstSurname;
         oracleCommand.Parameters.Add("SECOND_SURNAME_PARAMETER", OracleDbType.Varchar2).Value = commonUser.SecondSurname;
         oracleCommand.Parameters.Add("EMAIL_PARAMETER", OracleDbType.Varchar2).Value          = commonUser.Email;
         oracleCommand.Parameters.Add("PASSWORD_PARAMETER", OracleDbType.Blob).Value           = commonUser.Password;
         oracleCommand.Parameters.Add("SALT_PARAMETER", OracleDbType.Blob).Value = commonUser.Salt;
         Exception exceptionToReturn = null;
         try
         {
             oracleConnection.Open();
             oracleCommand.ExecuteNonQuery();
             oracleConnection.Close();
             return(exceptionToReturn);
         }
         catch (Exception exeption)
         {
             exceptionToReturn = exeption;
             oracleConnection.Close();
             return(exceptionToReturn);
         }
     }
 }
コード例 #19
0
 public Exception Login(string email, ref CommonUser commonUser)
 {
     using (OracleConnection oracleConnection = Connection.GetInstance().ConnectionDB())
     {
         OracleCommand oracleCommand = new OracleCommand();
         oracleCommand.Connection  = oracleConnection;
         oracleCommand.CommandText = "PACK_COMMON_USER.LOGIN";
         oracleCommand.CommandType = CommandType.StoredProcedure;
         oracleCommand.Parameters.Add("EMAIL", OracleDbType.Varchar2).Value = email;
         OracleDataReader oracleDataReader;
         Exception        exceptionToReturn = null;
         try
         {
             oracleConnection.Open();
             oracleDataReader = oracleCommand.ExecuteReader();
             while (oracleDataReader.Read())
             {
                 commonUser = Mapping(oracleDataReader);
             }
             return(exceptionToReturn);
         }
         catch (Exception exception)
         {
             exceptionToReturn = exception;
             return(exceptionToReturn);
         }
     }
 }
コード例 #20
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (cbPasswordChange.Checked)
            {
                if (!string.IsNullOrWhiteSpace(tbPassword.Text) && !string.IsNullOrWhiteSpace(tbPassword2.Text) && tbPassword.Text != tbPassword2.Text)
                {
                    labelError.Text    = "password_mismatch";
                    labelError.Visible = true;
                }
                else if (!string.IsNullOrEmpty(tbPassword.Text) && !string.IsNullOrEmpty(tbPassword2.Text) && tbPassword.Text == tbPassword2.Text)
                {
                    CommonUser newUser = new CommonUser();
                    newUser.Password   = tbPassword.Text;
                    newUser.AssignedTo = tbAssignedTo.Text;
                    newUser.OwnerId    = DataHolder.Owner.OwnerId;
                    Enums.UserRoles role;
                    Enum.TryParse(cbUserRole.SelectedValue.ToString(), out role);
                    newUser.Role   = (int)role;
                    newUser.UserId = OldUser.UserId;
                    var success = await SAUsers.PostEditUser(newUser);

                    if (success)
                    {
                        DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        labelError.Text    = "invalid_user";
                        labelError.Visible = true;
                    }
                }
                else
                {
                    labelError.Text    = "empty_username_or_password";
                    labelError.Visible = true;
                }
            }
            else
            {
                CommonUser newUser = new CommonUser();
                newUser.AssignedTo = tbAssignedTo.Text;
                newUser.OwnerId    = DataHolder.Owner.OwnerId;
                Enums.UserRoles role;
                Enum.TryParse(cbUserRole.SelectedValue.ToString(), out role);
                newUser.Role   = (int)role;
                newUser.UserId = OldUser.UserId;
                var success = await SAUsers.PostEditUser(newUser);

                if (success)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    labelError.Text    = "invalid_user";
                    labelError.Visible = true;
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Modify(CommonUser entity)
        {
            using (var context = new DbContext())
            {
                context.CommonUserContext.Update(entity);

                return(context.SaveChanges() > 0);
            }
        }
コード例 #22
0
ファイル: UserController.cs プロジェクト: C0dErBJ/YueDong
        public IHttpActionResult UpdateUserDetail([FromBody] CommonUser User)
        {
            var result = new BaseResult();

            result.ResultCode    = "1";
            result.ResultMessage = "Error";
            if (User == null)
            {
                result.ResultMessage = "用户不能为空";
                return(Ok(result));
            }
            if (User.Id == Guid.Empty)
            {
                result.ResultMessage = "UID不能为空";
                return(Ok(result));
            }

            var olduser = new CommonUserDAL().GetSingleById(User.Id);

            if (olduser == null)
            {
                result.ResultMessage = "未找到用户";
                return(Ok(result));
            }
            CommonUser newUser = olduser;

            if (User.Age != null)
            {
                newUser.Age = User.Age;
            }
            if (User.Gender != null)
            {
                newUser.Gender = User.Gender;
            }
            if (User.Hobby != null)
            {
                newUser.Hobby = User.Hobby;
            }
            if (User.NickName != null)
            {
                newUser.NickName = User.NickName;
            }
            newUser.UpdateTime = DateTime.Now;
            var results = new CommonUserDAL().Update(newUser);

            if (results)
            {
                result.ResultData    = newUser;
                result.ResultMessage = "Success";
                result.ResultCode    = "0";
            }
            else
            {
                result.ResultMessage = "修改成功";
            }
            return(Ok(result));
        }
コード例 #23
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Add(CommonUser entity)
        {
            using (var context = new DbContext())
            {
                context.CommonUserContext.Add(entity);

                return(context.SaveChanges() > 0);
            }
        }
コード例 #24
0
 //Создание формы и запуск тестирования
 public TestingForm(Test t, CommonUser user)
 {
     InitializeComponent();
     test    = new Test(t);
     Current = user;
     test.Ramdomize();
     QuestionBox.Text = test.Questions[currentQestion].TextOfQuestion;
     answerOptionsBindingSource.DataSource = test.Questions[currentQestion];
 }
コード例 #25
0
 public EditUserForm(CommonUser oldUser)
 {
     InitializeComponent();
     cbUserRole.DataSource    = Enum.GetValues(typeof(Enums.UserRoles));
     cbPasswordChange.Checked = false;
     gbPasswordChange.Enabled = false;
     OldUser           = oldUser;
     tbAssignedTo.Text = oldUser.AssignedTo;
     cbUserRole.Text   = oldUser.RoleString;
 }
コード例 #26
0
ファイル: UserRepository.cs プロジェクト: zzuqqiu/birdeye
        private static void GetHeadPortrait(string id, CommonUser user)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(HeadPortraitRootPath);
            var           fileList      = directoryInfo.GetFiles(id + ".*");

            if (fileList.Length > 0)
            {
                user.HeadPortrait = fileList[0].FullName;
            }
        }
コード例 #27
0
        public async Task <User> Register(CommonUser user, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            await DataContext.Users.AddAsync(user);

            return(user);
        }
コード例 #28
0
        public ActionResult SaveTeamPlayer(Player player)
        {
            player.TeamId = 1;
            DAL.SavePlayerByTeam(player);
            var        playerdetail = DAL.GetPlayerByTeam(1);
            CommonUser c            = new CommonUser();

            c.team        = new Team();
            c.team.player = playerdetail;
            return(View("Team", c));
        }
コード例 #29
0
        public async Task <IActionResult> ResetPassword([FromBody] ResetPasswordModel model)
        {
            var response = new APIResponse <ResetPasswordModel>()
            {
                Success = true
            };

            try
            {
                if (ModelState.IsValid)
                {
                    CommonUser user = await _commonUserSvc.CheckUser(model.Email);

                    if (user != null)
                    {
                        string token       = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                        var    callbackUrl = Url.Action("ResetPassword", "User", new { code = token });

                        using (var tx = CommonContext.Database.BeginTransaction())
                        {
                            user.Token    = token;
                            user.TokenUtc = DateTime.UtcNow;
                            CommonContext.Users.Update(user);

                            await CommonContext.SaveChangesAsync();

                            tx.Commit();
                        }

                        bool result = await _mailSvc.SendPasswordResetEmail(model.Email, callbackUrl);

                        response.Message = "Please check your email for a link to reset your password";
                    }
                    else
                    {
                        response.Message = "Please check your email for a link to reset your password";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Errors.AddRange(ModelState.ToErrors());
                }

                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                return(Ok(response));
            }
        }
コード例 #30
0
 private void btnEditUser_Click(object sender, EventArgs e)
 {
     if (dgvUsers.SelectedRows.Count == 1 && dgvUsers.SelectedRows[0] != null)
     {
         CommonUser   selectedItem = (CommonUser)dgvUsers.SelectedRows[0].DataBoundItem;
         EditUserForm form         = new EditUserForm(selectedItem);
         if (form.ShowDialog() == DialogResult.OK)
         {
             LoadData();
         }
     }
 }