コード例 #1
0
ファイル: ResetPassword.cs プロジェクト: Naimaoye/Edufund
 public resetPasswordResponse resetPassword(long userid, IHostingEnvironment env, IConfiguration _config)
 {
     try
     {
         using (var db = new DBConnect.TrippleNTDBContext())
         {
             var user = db.CompanyStaff.Find(userid);
             if (user == null)
             {
                 return new resetPasswordResponse {
                            status = "failed", msg = "user not found"
                 }
             }
             ;
             else
             {
                 if (user.UserType == "Admin")
                 {
                     var password = Utility.Encryptor.GeneratePassword(6);
                     user.Password  = Utility.Encryptor.EncodePasswordMd5(password);
                     user.UseStatus = true;
                     db.CompanyStaff.Attach(user);
                     db.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                     db.SaveChanges();
                     var comp = db.Company.Find(user.CompanyId);
                     var msg  = "Hello, " + comp.Name + ", <br> We are glad to have you on our EduFund crowdfunding Platform. <br>Kindly see your new  credentials below <br><b>User Id: " + comp.PhoneNumber + "</b><br> <b>  Password: "******"  </b><br><br>#ChangeTheWorldWithYourSpareChange <br><br>Regards,<br> Admin Edufund";
                     Utility.SendMail.Send("Welcome to EduFund", msg, comp.Email, _config);
                     return(new resetPasswordResponse {
                         status = "success", msg = "Password Reset Successful"
                     });
                 }
                 else
                 {
                     var password = Utility.Encryptor.GeneratePassword(6);
                     user.Password  = password;
                     user.UseStatus = true;
                     db.CompanyStaff.Attach(user);
                     db.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                     db.SaveChanges();
                     return(new resetPasswordResponse {
                         status = "success", msg = "Password Reset Successful"
                     });
                 }
             }
         }
     }
     catch (Exception ex)
     {
         new Utility.LogWriter(ex.Message + " " + ex.InnerException, env);
         return(new resetPasswordResponse {
             status = "failed", msg = "Something went wrong try again later"
         });
     }
 }
コード例 #2
0
        public changePasswordResponse changePassword(changePasswordPayLoad payload, IHostingEnvironment env, IConfiguration _config)
        {
            try
            {
                using (var db = new DBConnect.TrippleNTDBContext())
                {
                    var user = db.CompanyStaff.Find(payload.userId);
                    if (user == null)
                    {
                        return new changePasswordResponse {
                                   status = "failed", msg = "user not found"
                        }
                    }
                    ;
                    else
                    {
                        if (user.UserType == "Admin")
                        {
                            if (Utility.Encryptor.EncodePasswordMd5(user.Password) == Utility.Encryptor.EncodePasswordMd5(payload.oldPassword))
                            {
                                user.Password  = Utility.Encryptor.EncodePasswordMd5(payload.newPassword);
                                user.UseStatus = false;
                                db.CompanyStaff.Attach(user);
                                db.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                                db.SaveChanges();
                                var comp = db.Company.Find(user.CompanyId);
                                var msg  = "Hello, " + comp.Name + ", <br> Tis to notify you that your password change was successful <br> Thanking for being part of this quest of making an impact in the world.<br><br>#ChangeTheWorldWithYourSpareChange <br><br>Regards,<br> Admin Edufund";
                                Utility.SendMail.Send("Welcome to EduFund", msg, comp.Email, _config);
                                return(new changePasswordResponse {
                                    status = "success", msg = "P Changed Successfully"
                                });
                            }
                            else
                            {
                                return new changePasswordResponse {
                                           status = "failed", msg = "Invalid Old Password"
                                }
                            };
                        }
                        else
                        {
                            if (user.UseStatus)
                            {
                                if (user.Password == payload.oldPassword)
                                {
                                    user.Password  = Utility.Encryptor.EncodePasswordMd5(payload.newPassword);
                                    user.UseStatus = false;
                                    db.CompanyStaff.Attach(user);
                                    db.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                                    db.SaveChanges();
                                    return(new changePasswordResponse {
                                        status = "success", msg = "Password Changed Successfully"
                                    });
                                }
                                else
                                {
                                    return new changePasswordResponse {
                                               status = "failed", msg = "Invalid Old Password"
                                    }
                                };
                            }
                            else
                            {
                                if (Utility.Encryptor.EncodePasswordMd5(user.Password) == Utility.Encryptor.EncodePasswordMd5(payload.oldPassword))
                                {
                                    user.Password = Utility.Encryptor.EncodePasswordMd5(payload.newPassword);

                                    user.UseStatus = false;
                                    db.CompanyStaff.Attach(user);
                                    db.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                                    db.SaveChanges();
                                    return(new changePasswordResponse {
                                        status = "success", msg = "Password Changed Successfully"
                                    });
                                }
                                else
                                {
                                    return new changePasswordResponse {
                                               status = "failed", msg = "Invalid Old Password"
                                    }
                                };
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                new Utility.LogWriter(ex.Message + " " + ex.InnerException, env);
                return(new changePasswordResponse {
                    status = "failed", msg = "Something went wrong try again later"
                });
            }
        }