Browse Source

修改学生信息。修改学生密码。

CrazyIter_Bin 3 years ago
parent
commit
a9d304c370

+ 4 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/GroupList.cs

@@ -39,6 +39,10 @@ namespace TEAMModelOS.SDK.Models
         /// 头像
         /// </summary>
         public string picture { get; set; }
+        /// <summary>
+        /// IRS WebIRS编号。
+        /// </summary>
+        public string no { get; set; }
        // public string role { get; set; }
     }
 }

+ 4 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/Student.cs

@@ -24,6 +24,10 @@ namespace TEAMModelOS.SDK.Models
         public string groupId { get; set; }
         public string groupName { get; set; }
         public string periodId { get; set; }
+        /// <summary>
+        /// 性别 m( male,男) f (female 女)  n(secret 保密) 
+        /// </summary>
+        public string gender { get; set; }
         //补充留级信息
         //0在校,1留级,2退学 3毕业
         public int status { get; set; } = 0;

+ 64 - 5
TEAMModelOS/Controllers/School/StudentController.cs

@@ -58,8 +58,8 @@ namespace TEAMModelOS.Controllers
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        [AllowAnonymous]
         [HttpPost("student-manage")]
+        [AuthToken(Roles = "admin,student,teacher")]
         public async Task<IActionResult> StudentManage(JsonElement request)
         {
             try
@@ -180,7 +180,7 @@ namespace TEAMModelOS.Controllers
                     case "avatar":
                         if (request.TryGetProperty("avatar", out JsonElement _avatar) && _avatar.ValueKind.Equals(JsonValueKind.Array))
                         {
-                            List<Avatar> avatars = _avatar.ToObject<List<Avatar>>();
+                            List<StudentInfo> avatars = _avatar.ToObject<List<StudentInfo>>();
                             if (avatars.IsNotEmpty())
                             {
                                 List<Student> studentsp = new List<Student>();
@@ -194,7 +194,7 @@ namespace TEAMModelOS.Controllers
                                 (string url, string sas) = _azureStorage.GetBlobContainerSAS99Year($"{schoolId}", BlobContainerSasPermissions.Read);
                                 foreach (Student student in studentsp)
                                 {
-                                    Avatar avatar = avatars.Find(x => x.studentId.Equals(student.id));
+                                    StudentInfo avatar = avatars.Find(x => x.studentId.Equals(student.id));
                                     student.picture = avatar != null ? $"{avatar.picture}?{sas}" : null;
                                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<Student>(student, student.id, new PartitionKey(student.code));
                                 }
@@ -209,7 +209,58 @@ namespace TEAMModelOS.Controllers
                         {
                             return BadRequest();
                         }
-
+                    case "update-self-info":
+                        if (request.TryGetProperty("studentInfo", out JsonElement _studentInfo))
+                        {
+                            var studentInfo = _studentInfo.ToObject<StudentInfo>();
+                            Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                .ReadItemAsync<Student>(studentInfo.studentId, new PartitionKey($"Base-{schoolId}"));
+                            student.mail = string.IsNullOrEmpty(studentInfo.mail) ? "" : studentInfo.mail;
+                            student.mobile = string.IsNullOrEmpty(studentInfo.mobile) ? "" : studentInfo.mobile;
+                            student.name = string.IsNullOrEmpty(studentInfo.name) ? "" : studentInfo.name;
+                            student.picture = string.IsNullOrEmpty(studentInfo.picture) ? "" : studentInfo.picture;
+                            student.gender = string.IsNullOrEmpty(studentInfo.g) ? "" : studentInfo.;
+                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                .ReplaceItemAsync<Student>(student, studentInfo.studentId, new PartitionKey($"Base-{schoolId}"));
+                            return Ok(new { studentInfo });
+                        }
+                        else {
+                            return BadRequest();
+                        }
+                    case "update-self-password":
+                        if (request.TryGetProperty("newpwd", out JsonElement _newpwd)&& 
+                            request.TryGetProperty("oldpwd", out JsonElement _oldpwd) && 
+                            request.TryGetProperty("studentId", out JsonElement _studentId)) {
+                            Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                .ReadItemAsync<Student>($"{_studentId}", new PartitionKey($"Base-{schoolId}"));
+                            var HashedPW = Utils.HashedPassword($"{_oldpwd}", student.salt);
+                            if (HashedPW.Equals(student.pw))
+                            {
+                                student.pw = Utils.HashedPassword($"{_newpwd}", student.salt);
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                              .ReplaceItemAsync<Student>(student, student.id, new PartitionKey($"Base-{schoolId}"));
+                                return Ok(new {status=true, });
+                            }
+                            else {
+                                return Ok(new { });
+                            }
+                        }
+                        else
+                        {
+                            return BadRequest();
+                        }
+                    case "read-self-info":
+                        if (request.TryGetProperty("studentId", out JsonElement __studentId))
+                        {
+                            Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                .ReadItemAsync<Student>($"{__studentId}", new PartitionKey($"Base-{schoolId}"));
+                            
+                            return Ok(new { student.mail, student.mobile, student.name, student.picture, student.gender, student.id, student.schoolId, student.year, student.no, student.classId, student.periodId });
+                        }
+                        else
+                        {
+                            return BadRequest();
+                        }
                     default:
                         return BadRequest();
                 }
@@ -651,10 +702,18 @@ namespace TEAMModelOS.Controllers
             return dictChange; 
         }
 
-        public record Avatar
+        public record StudentInfo
         {
             public string studentId { get; set; }
             public string picture { get; set; }
+            public string name { get; set; }
+            public string mobile { get; set; }
+            public string mail { get; set; }
+            /// <summary>
+            /// f女性 m男性 n 保密 
+            /// </summary>
+            public string gender { get; set; }
+            
         }
         /// <summary>
         /// 整理前端匯入的學生資訊