Changeset 572 in code for trunk/service.go


Ignore:
Timestamp:
Jun 28, 2021, 4:05:03 PM (4 years ago)
Author:
contact
Message:

Introduce user.updateUser

Unify updatePassword and updateRealname into a single function. This
allows "user update" to be atomic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/service.go

    r570 r572  
    776776        }
    777777
     778        // copy the user record because we'll mutate it
     779        record := dc.user.User
     780
    778781        if password != nil {
    779782                hashed, err := bcrypt.GenerateFromPassword([]byte(*password), bcrypt.DefaultCost)
     
    781784                        return fmt.Errorf("failed to hash password: %v", err)
    782785                }
    783                 if err := dc.user.updatePassword(string(hashed)); err != nil {
    784                         return err
    785                 }
     786                record.Password = string(hashed)
    786787        }
    787788        if realname != nil {
    788                 if err := dc.user.updateRealname(*realname); err != nil {
    789                         return err
    790                 }
     789                record.Realname = *realname
     790        }
     791
     792        if err := dc.user.updateUser(&record); err != nil {
     793                return err
    791794        }
    792795
Note: See TracChangeset for help on using the changeset viewer.